Incorrect syntax

crompnk
crompnk used Ask the Experts™
on
Hi,

When I run the attached bat file with batch commands I sometimes get the following error and the file isn't renamed:

'The syntax of the command is incorrect'

I don't always get this error, the syntax is correct, I need to restart the computer for it to work again.
Can anything be done to solve this.

Thank you
TestFile.bat.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technology and Business Process Advisor
Most Valuable Expert 2013
Commented:
Off hand, I'd say you have the quote in the wrong place.

you have:
ren "C:\Temp\Test\TestFile.txt" "TestFile"_%Date:/=-%_%Time::=-%.txt
type nul >"C:\Temp\Test\TestFile.txt"

what is wrong (highlighted with *):
ren "C:\Temp\Test\TestFile.txt" "TestFile*"*_%Date:/=-%_%Time::=-%.txt
type nul >"C:\Temp\Test\TestFile.txt"

should be:
ren "C:\Temp\Test\TestFile.txt" "TestFile_%Date:/=-%_%Time::=-%.txt"
type nul >"C:\Temp\Test\TestFile.txt"

Of course, if that doesn't solve your problem, then post a screen shot with the error message you're getting - given that you don't use echo off, it should essentially TELL you what line it's erroring out on and show the actual command it's trying to execute.
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
Also, I don't know if REN supports PATHs... I'd suggest CDing into the folder then running ren on JUST the file name.

Commented:
ren "C:\Temp\Test\TestFile.txt" "TestFile_%Date:/=-%_%Time::=-%.txt"
type nul >"C:\Temp\Test\TestFile.txt"
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
t0t0... isn't that what I said?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
leew,
FYI, REN supports path (in the source part only, the destination may not contain path info).


Commented:
leew - probably, I didn't look, but if it is then it's confirmed then isn't it? Two experts in agreement can't be wrong can they eh? :)


Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
@Qlemo,

Didn't test it today - obviously it would've been easy enough to test.  But that probably explains why I wasn't remembering exactly...

@t0t0.

I have no problem with people posting confirmations... and I have no problem with people posting the same thing (essentially) at (generally) the same time... once recently there was a question answered by 4 people with the same answer during the same minute... but when people post 30 minutes after I do and fail to acknowledge my comment, that's inappropriate in my opinion.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial