Batch file renaming using file version

March 29, 2012 at 05:47:48
Specs: Windows XP
I have a batch file I am writing and I have a mid level understanding of MS-DOS. This batch file is going to be part of a startup script for a program to check for new versions on a server, if a new version exists rename the old file (code below) using the file version. Then it will copy the new version from the server and launch the program.
I have everything working right, and was able to rename files using %date% but decided using file version was a better route. However I'm stuck trying to get it to work properly from the batch file. It works fine from a CMD prompt, but fails in a batch file.

I can get the following code to work in a CMD prompt... it works perfectly!
FOR /F "tokens=1-11 delims= " %g in ('filever ^"C:\Program Files\GE\Start Stop\Start Stop Dryer.exe^"') DO REN "C:\Program Files\GE\Start Stop\Start Stop Dryer.exe" "Start Stop Dryer%k.exe"

But when I edit it and add the double % to use in a batch file.....
FOR /F "tokens=1-11 delims= " %%g in ('filever ^"C:\Program Files\GE\Start Stop\Start Stop Dryer.exe^"') DO RENAME "C:\Program Files\GE\Start Stop\Start Stop Dryer.exe" "Start Stop Dryer%%k.exe"

The batch file doesn't run. It hangs up for about 30-60 secs then I get a never ending scroll of "The syntax of the command is incorrect". It never ends, and even a CTRL C to terminate doesn't work. I have to close the CMD window without the batch file completing.

I've used this forum for a lot of advice to write my entire script, so I thought I'd post this one up and see if someone can help?


See More: Batch file renaming using file version

Report •


#1
March 29, 2012 at 06:27:43
Remove the ^ before " since double quotes are allowed in a clause embraced by '.

Report •

#2
March 29, 2012 at 08:51:02
Thanks for the sugggestion but that did not work either.
Same results, it does not rename the file and the output on the CMD screen is still a never ending scroll of "The syntax of the command is not correct."

Also I found on another site this info...
"In the example the long filename has to be surrounded in "quotes"
these quotes have to be escaped using ^"


Report •

#3
April 12, 2012 at 03:54:14
Answer can be found on this thread.....

http://www.computing.net/answers/pr...


Report •

Related Solutions

#4
April 12, 2012 at 06:31:37
I guess that explains why it worked in the prompt, you always chose the correct directory from there.

mike


Report •

Ask Question