batch file - filename variable causing issue with counter in loop -


situation:i receive files everyday name dfadv* (*=a 2 or 3 digit number , no extension). file them manually 1 month @ time. (i have separate .bat archive each month me). each day original draft file, second iteration of sent draft file, or "final" file. need move them specified ftp folders each recipients folder path, (7 recipients). have following code me except file name variable generic , messes count iterations properly.

echo on rem searches each file line word draft indicates rem files type, etc final. else old files haven't changed /f %%i in ('findstr /i /m "draft" dfadv*.*') move "%%i" draft rem pause /f %%i in ('findstr /i /m "final" dfadv*.*') move "%%i" final rem pause move d:\ftp\colby\holding\dfadv*.* d:\ftp\colby\holding\current  set sourced=d:\ftp\colby\holding\draft\*.* set sourcef=d:\ftp\colby\holding\final\*.* set sourcec=d:\ftp\colby\holding\current\*.* set dest001draft=d:\ftp\colby\order001\draft\ set dest001final=d:\ftp\colby\order001\final\ set dest001curr=d:\ftp\colby\order001\current\ set dest007draft=d:\ftp\colby\order007\draft\ set dest007final=d:\ftp\colby\order007\final\ set dest007curr=d:\ftp\colby\order007\current\ set dest030draft=d:\ftp\colby\order030\draft\ set dest030final=d:\ftp\colby\order030\final\ set dest030curr=d:\ftp\colby\order030\current\ set dest032draft=d:\ftp\colby\order032\draft\ set dest032final=d:\ftp\colby\order032\final\ set dest032curr=d:\ftp\colby\order032\current\ set dest033draft=d:\ftp\colby\order033\draft\ set dest033final=d:\ftp\colby\order033\final\ set dest033curr=d:\ftp\colby\order033\current\ set dest124draft=d:\ftp\colby\order124\draft\ set dest124final=d:\ftp\colby\order124\final\ set dest124curr=d:\ftp\colby\order124\current\ set dest126draft=d:\ftp\colby\order126\draft\ set dest126final=d:\ftp\colby\order126\final\ set dest126curr=d:\ftp\colby\order126\current\ set destfilerecdraft=d:\ftp\colby\holding\filesrec\draft\ set destfilerecfinal=d:\ftp\colby\holding\filesrec\final\ set destfilereccurr=d:\ftp\colby\holding\filesrec\current\ set filename=*.* set a=0 rem pause :loop if exist %dest001draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest001draft%\%filename%(%a%).txt rem pause if exist %dest001final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest001final%\%filename%(%a%).txt rem pause if exist %dest001curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest001curr%\%filename%(%a%).txt  if exist %dest007draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest007draft%\%filename%(%a%).txt rem pause if exist %dest007final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest007final%\%filename%(%a%).txt rem pause if exist %dest007curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest007curr%\%filename%(%a%).txt  if exist %dest030draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest030draft%\%filename%(%a%).txt rem pause if exist %dest030final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest030final%\%filename%(%a%).txt rem pause if exist %dest030curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest030curr%\%filename%(%a%).txt  if exist %dest032draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest032draft%\%filename%(%a%).txt rem pause if exist %dest032final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest032final%\%filename%(%a%).txt rem pause if exist %dest032curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest032curr%\%filename%(%a%).txt  if exist %dest033draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest033draft%\%filename%(%a%).txt rem pause if exist %dest033final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest033final%\%filename%(%a%).txt rem pause if exist %dest033curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest033curr%\%filename%(%a%).txt  if exist %dest124draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest124draft%\%filename%(%a%).txt rem pause if exist %dest124final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest124final%\%filename%(%a%).txt rem pause if exist %dest124curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest124curr%\%filename%(%a%).txt   if exist %dest126draft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %dest126draft%\%filename%(%a%).txt rem pause if exist %dest126final%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %dest126final%\%filename%(%a%).txt rem pause if exist %dest126curr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %dest126curr%\%filename%(%a%).txt  if exist %destfilerecdraft%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourced% %destfilerecdraft%\%filename%(%a%).txt rem pause if exist %destfilerecfinal%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcef% %destfilerecfinal%\%filename%(%a%).txt rem pause if exist %destfilereccurr%\%filename%(%a%).txt set /a a+=1 && goto :loop copy %sourcec% %destfilereccurr%\%filename%(%a%).txt  pause  del %sourced% del %sourcef% del %sourcec%  pause 

below issue,

dfadv86.(0)  {note: day 1} dfadv64.(1)  {note: added second day if there no other files                     , first time receiving dv64} 

on second day run second iteration "(1)" if file doesn't exist. i believe finding match my

set filename=*.* 

and counting match. how go getting search each file in holding folder specifically.

possible solutions not sure how make work.

1) make second line of code bat creates list file of files need , re work reference txt file

echo on start listfile.bat 

listfile.bat

dir /b d:\ftp\colby\holding\dfadv*.* > fileslist.txt exit 

2) how set filenames better variables/lists/arrays... have no clue how that. n00b programmer has stitched other stuff have found online.

thank in advance can offer.

i changed way runs instead of looping iterations on line had call bat program.

echo on 8:30 7/16/2015 :: search  files  string draft ::pause /f %%i in ('findstr /i /m "draft" dfadv*.*') call draft.bat "%%~i" ::pause :: search  files  string final /f %%i in ('findstr /i /m "final" dfadv*.*') call final.bat "%%~i"  ::pause :: if neither draft or final found move current folder,  :: these files havent been  :: converted. should 2 digit division number.  :: if 3 digit division code  :: found there issue file or batch script refernce draft or final.  :: moving old format current root folder ::pause move d:\ftp\colby\holding\dfadv*.* d:\ftp\colby\holding\current :: moving old format dairylea ::pause move d:\ftp\colby\holding\div*.* d:\ftp\colby\holding\current :: set file paths variables batch script ::pause set sourced=d:\ftp\colby\holding\draft\ set sourcef=d:\ftp\colby\holding\final\ set sourcec=d:\ftp\colby\holding\current\ set dest001draft=d:\ftp\colby\order001\draft\ set dest001final=d:\ftp\colby\order001\final\ set dest001curr=d:\ftp\colby\order001\current\ set dest007draft=d:\ftp\colby\order007\draft\ set dest007final=d:\ftp\colby\order007\final\ set dest007curr=d:\ftp\colby\order007\current\ set dest030draft=d:\ftp\colby\order030\draft\ set dest030final=d:\ftp\colby\order030\final\ set dest030curr=d:\ftp\colby\order030\current\ set dest032draft=d:\ftp\colby\order032\draft\ set dest032final=d:\ftp\colby\order032\final\ set dest032curr=d:\ftp\colby\order032\current\ set dest033draft=d:\ftp\colby\order033\draft\ set dest033final=d:\ftp\colby\order033\final\ set dest033curr=d:\ftp\colby\order033\current\ set dest124draft=d:\ftp\colby\order124\draft\ set dest124final=d:\ftp\colby\order124\final\ set dest124curr=d:\ftp\colby\order124\current\ set dest126draft=d:\ftp\colby\order126\draft\ set dest126final=d:\ftp\colby\order126\final\ set dest126curr=d:\ftp\colby\order126\current\ set destfilerecdraft=d:\ftp\colby\holding\filesrec\draft\ set destfilerecfinal=d:\ftp\colby\holding\filesrec\final\ set destfilereccurr=d:\ftp\holding\filesrec\current\ ::pause ::copy files in holding draft  folder each orders correct draft folder copy %sourced%*.* %dest001draft% copy %sourced%*.* %dest007draft% copy %sourced%*.* %dest030draft% copy %sourced%*.* %dest032draft% copy %sourced%*.* %dest033draft% copy %sourced%*.* %dest124draft% copy %sourced%*.* %dest126draft% ::copy files in holding\final  folder each orders correct final folder copy %sourcef%*.* %dest001final% copy %sourcef%*.* %dest007final% copy %sourcef%*.* %dest030final% copy %sourcef%*.* %dest032final% copy %sourcef%*.* %dest033final% copy %sourcef%*.* %dest124final% copy %sourcef%*.* %dest126final% ::copy files in holding\cur  folder each orders correct current folder copy %sourcec%*.* %dest001curr% copy %sourcec%*.* %dest007curr% copy %sourcec%*.* %dest030curr% copy %sourcec%*.* %dest032curr% copy %sourcec%*.* %dest033curr% copy %sourcec%*.* %dest124curr% copy %sourcec%*.* %dest126curr% ::move each itteration files received corresponidng folders month. move %sourced%*.* %destfilerecdraft% move %sourced%*.* %destfilerecfinal% move %sourced%*.* %destfilereccurr% 

here draft.bat

:: draft.bat 8:32 7/16/2015 :: echo off :: echo file passed "%~1".(0) echo on set filea=%~1 ::pause echo:%filea% ::checking see if file has been processed ::the move command renames correct version of file ::pause :: echo if exist d:\ftp\colby\order001\draft\%filea%.(0) goto check(1) ::pause if exist d:\ftp\colby\order001\draft\%filea%.(0) goto check(1) ::pause :: echo move d:\ftp\colby\holding\%filea% d:\ftp\colby\holding\draft\%filea%.(0) move d:\ftp\colby\holding\%filea% d:\ftp\colby\holding\draft\%filea%.(0) ::pause  goto eof  ::checking see if file has been processed twice :check(1) if exist d:\ftp\colby\order001\draft\%filea%.(1) goto check(2) move d:\ftp\colby\holding\%filea%  d:\ftp\colby\holding\draft\%filea%.(1) goto eof  ::checking see if file has been processed 3 times :check(2) if exist d:\ftp\colby\order001\draft\%filea%.(2) goto check(3) move d:\ftp\colby\holding\%filea%  d:\ftp\colby\holding\draft\%filea%.(2) goto eof  ::checking see if file has been processed 4 times :check(3) if exist d:\ftp\colby\order001\draft\%filea%.(3) goto check(4) move d:\ftp\colby\holding\%filea% d:\ftp\colby\holding\draft\%filea%.(3) goto eof ::checking see if file has been processed 5 times :check(4) if exist d:\ftp\colby\order001\draft\%filea%.(4) goto check(5) move d:\ftp\colby\holding\%filea% d:\ftp\colby\holding\draft\%filea%.(4) goto eof ::checking see if file has been processed 6 times :check(5) if exist d:\ftp\colby\order001\draft\%filea%.(5) goto echo1 move d:\ftp\colby\holding\%filea% d:\ftp\colby\holding\draft\%filea%.(5) goto eof  :echo1 echo "error have set 0-5 need more itterations!" ::pause  

:eof ::pause exit /b

final.bat same.


Comments