1.

Solve : creating filename with date?

Answer»

I have searched through this site and found this code that looked like it should work in reference CH000987:

for /f "tokens=2-4 delims=/ " %%a in ('date/t') do rename "extrfile.dat" extrfile_%%a-%%b-%%c.dat

I am getting the error "%%a was unexpected at this time".

SUGGESTIONS please??

I am RUNNING on Windows XP
What is it your trying to do???

I think you've missed the ( ) in the for loop. Try;


for /f "tokens=2-4 delims=/ " %%a in ('date/t') do (
rename "extrfile.dat" extrfile_%%a-%%b-%%c.dat
)

I am trying to keep a back up file with the date it was created in the filename.
I'll try adding the ()s

for /f "tokens=2-4 delims=/ " %%a in ('date/t') do (rename "extrfile.dat" extrfile_%%a-%%b-%%c.dat)

same error "%%a was unexpected at this time."are you running this from the command prompt or from a batch file??At the moment I am running from Command Prompt but ultimately want to run from a batch file.blastman's question about WHETHER I was running from command prompt or batch file led me to try it from the batch file --- and it works!! Nothing wrong with the code, only where I was running it from.

Thanks, Blastman!!not a PROBLEM mate.

the For command requires you use just one % when running from the prompt, but when running from a batch file you have to add an extra %.

Glad it's working now.yes, the date is working.
but now I'm going to complicate things and want to add the time - hour,min, second.
I'm trying to scope it out on my own but if you have the code for this already...
I'm SUPPOSING I need to set the date elements aside and the time elements and then put them all together?
Can you help??



Discussion

No Comment Found