0

The following works in Command Line but the second one fails in the Batch script. By fails I mean that it exit the .Bat immediately. Does not even stop at a PAUSE immediately following the FOR /F ...... executing line.

Console:

FOR /F "TOKENS=1 delims="  %I IN ('Dir *.Properties /B') DO (If NOT EXIST ..\Working\%~nI_ru.properties copy %~nI.properties ..\New_Files\%~nI_ru.properties)

Batch file:

FOR /F "TOKENS=1 delims=" %%I IN ('Dir *.Properties /B') DO (If NOT EXIST ..\Working\%%~nI_ru.properties copy %%~nI.properties ..\New_Files\%%~nI_ru.properties)

It is comparing two software version releases and selecting those 'new' property files available and copying them to a New_File directory with filename change. ThisIsANewFile.properties is copied as ThisIsANewFile**_ru**.properties i.e. _ru appended to the FileName

Thanks to anyone who knows what I've done wrong,

Alex
  • 897
  • 5
  • 11
  • 1
    Please surround your code with code-tags – DBedrenko May 25 '14 at 09:50
  • Do your filenames contain spaces or `&` characters? If so then the terms will need to be quoted. Open a cmd window and launch the batch file. You will see the error messages. – foxidrive May 25 '14 at 11:56

1 Answers1

0

Seems like you're script has a hard time locating the files that's it's trying to copy since the batch file usually starts in C:\Windows\System32\ try adding cd /d %~dp0 before your for /f loop. Like so:

cd /d %~dp0
FOR /F "TOKENS=1 delims=" %%I IN ('Dir *.Properties /B') DO (If NOT EXIST ..\Working\%%~nI_ru.properties copy %%~nI.properties ..\New_Files\%%~nI_ru.properties)

%~dp0 is gives you the location where the batch file was called from. See %~dp0 SO link

You can also use absolute paths. for example Dir C:\MyApp\*.Properties /B

Community
  • 1
  • 1
Alex
  • 897
  • 5
  • 11