8 replies
by joseph moore
Yes, you can use a FOR command to parse out the DATE command, then issue a REN using the output! It took me a while to figure this out a year ago (I had to archive pictures from a webcam) but I was successful.
Ok, say your file is called FILE.LOGand you moved it into C:\FILES
Now, to rename this file, put the following lines in your BAT file after the file has been moved:
C:
CD \
CD FILES
FOR /F "tokens=1-4 delims=/ " %%i in ('date /t') do set filerename=%%i%%j%%k%%l
RENAME file.log %filerename%.log
There, that's it! That will CD into the C:\FILES directory, and take the file FILE.LOG and rename it to Thu03062003.log. The FOR line parses out the DATE /T command, assigning "Thu" to %%i, "03"
to %%j, "06" to %%k, and "2003" to %%l. After that, the whole mess is pressed together into the new variable "filerename". You then just have to rename your original LOG file to be %filerename%.log.
Now, if you don't want the day of the week in the file name (the "Thu" part inthe example), just change the FOR /F file at the end to read, "do set filerename=%%j%%k%%l"
You can also shuffle the variables around if you want the year set first. Just have fun with this.
hope this helps
by joseph moore
Here is a clarification on the FOR /F command.
IF you want to run this line from a Command Prompt, you have to use only a single "%" for each variable.
But, if you want to run this in a BAT file, you have to use "%%".
This is a difference in using the FOR command.
So, the Command line version would be:
FOR /F "tokens=1-4 delims=/ " %i in ('date /t') do set filerename=%i%j%k%l
And the BAT file version is like I posted above.
I don't know why it works this way. It just does, to my chagrin!
hope this clears things up.
Joe
by cvn70_it2
by cvn70_it2
by cvn70_it2
by cvn70_it2
by cvn70_it2
Joe, I made the appropriate changes like you had pointed out, but it still isn't working. Here is what my batch looks like. Am I doing something wrong?
c:
copy c:\folder1\test.log c:\folder2
cd c:\folder2
FOR /F "tokens=1-4 delims=/ " %%i in ('date /t') do set filerename=%%i%%j%%k%%l
RENAME file.log %filerename%.log
It copies it, but it won't rename. I feel like I'm so close! Thanks again. AJ
by cvn70_it2
This discussion is closed to new replies.
Trending Windows Forum posts
Sort by Trending