Script to move files based on Pattern don't work

Hi people,

i need you help on this if you can.

I have a script that does the move command when it searches for a that doesn't match the pattern. This Pattern is on a list.

When it run's and doesn�t found no files but it haves 2 more folders it moves the folders too.

Ex:
WORKDIR=R:/mdi_prod
SCRIPTS=R:/Deployment/MDI/PROD
LOGS=$SCRIPTS/LOGS
CONF=conf_file_FTP.conf
GETF=`cat $SCRIPTS/$CONF`
stamp=`/usr/bin/date +"%Y%m%d%H%M"`

####################################### **** FUNCOES ***

##################################################

cd $WORKDIR

for i in $GETF
do
teste1=`echo $i | awk -F ';' '{print $1}'`
echo $teste1 >> $LOGS/Check_files_1_$stamp.log
teste2=`echo $i | awk -F ';' '{print $2}'`
echo $teste2 >> $LOGS/Check_files_1_$stamp.log
teste3=`echo $i | awk -F ';' '{print $3}'`
echo $teste3 >> $LOGS/Check_files_1_$stamp.log
cd $WORKDIR/$teste2 >> $LOGS/Check_files_1_$stamp.log
basico=`ls -I "$teste3" | grep -v Historico`
echo $basico >> $LOGS/Check_files_1_$stamp.log
for j in `echo $basico`
do
cp $WORKDIR/$teste2/$j $WORKDIR/ERROR_FILES >> $LOGS/Check_files_1_$stamp.log
sleep 5
done
echo cd $WORKDIR >> $LOGS/Check_files_1_$stamp.log

done
exit

The list :

FRROGET;edpst/Forwards/Reuters/Reuters_Others;????????_Reuters_Forward_Others.xls
CURGET;edpst/Previsiones/CUR;CUR_????????v*.xls
PMPTGET;edpst/Previsiones/MIBEL_PT;prev_portugal
????????.xls
POGET;edpst/Previsiones/OMIP;OMIPdaily_??-??-????.xls
NESPGET;NEO_ESPANHA;AS_????????.xls
NPCNGET;NEO_ESPANHA/PREV_COGEN_NEO;REMercado_????????.red
NEOFREDFGET;NEO_FRANCA/curvas_EDF;EDF
.txt
NEOFRANCURVDGET;NEO_FRANCA;0000*.cdc
CONSANPREVGET;HC/CONSUMO_ANUAL_PREVISTO;CONSUMO_ANUAL_PREVISTO_*.csv
CPEENERGET;EOL_PORTUGAL/CargadorProdEEEnernova;PE_Enernova_??_a_????????.xls
CPEESPTGET;EOL_PORTUGAL/CargadorProdEESubestacionPT;PE_Agregados_SE_?????_???????.xls

For example, the folder NEO_ESPANHA all files that doesn't match the pattern " AS_????????.xls" but me moved to a folder of ERROR_FILES. What appens is it move the subfolders too when i do a ( ls -I "AS_????????.xls" ).

I'm doing this on the Cygwin tool.

Can someone help me ?

Regards

osramos

I think you need to have no space between -I and the pattern to ignore, e.g.:

basico=`ls -I"$teste3" | grep -v Historico`

You can make sure it is a file before copying it by doing something like this:

[[ -f $WORKDIR/$teste2/$j ]] && cp $WORKDIR/$teste2/$j $WORKDIR/ERROR_FILES >> $LOGS/Check_files_1_$stamp.log