0
I thought this would be simple but it seems more of a challenge than I thought.
I want a file to be copied and pasted with a time stamp appended. I get the time stamp using this code:
set hournum=%time:~0,2%
if %hournum% gtr 9 (set timeback=_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%h%time:~3,2%m%time:~6,2%s) else (set timeback=_%date:~10,4%%date:~4,2%%date:~7,2%_0%time:~1,1%h%time:~3,2%m%time:~6,2%s)
Set FileAffected=%1
echo %FileAffected:~0,-1%%timeback%
This would make the file, FILE.TXT
be FILE.TXT_2015-03-05_11h56m32s
But I obviously want it to be FILE_20150305_11h56m32s.TXT
The file extension could be any extension or any length. Thanks for any help.
EDIT: FileAffected is passed with quotes, so I just stripped them with the ~0,-1.
I did find that if I do this:
FOR /f %%i IN (%FileAffected%) DO (
ECHO filename=%%~fi
ECHO fileextension=%%~xi
)
If I echo FileAffected I get the full path name with spaces. But if I use the FOR /F command, the filename comes back truncating anything after a space. Even adding extra quotes to the "%FileAffected" variable in the "IN" command, still doesn't fix it, nor does adding quotes around the fi or xi.
Note:
%timeback%
does not include the year for me. I get_3/01_18h31m52s
on my system, where%date%
is15/03/2015
– DavidPostill – 2015-03-15T17:33:48.163Thank you for taking the time to answer. I will have to trial this later when I get a chance. Weird because I have this same "%timeback%" variable with another batch giving me year. I'll have to look deeper. – HTWingNut – 2015-03-26T00:18:51.667
Thank you for taking the time to answer. I will have to trial this later when I get a chance. I guess your date format is dd/mm/yyyy where in good ol' USA where we do everything backwards it's mm/dd/yyyy. Will have to ponder that one for a bit. http://i.imgur.com/WIKf6TE.jpg
– HTWingNut – 2015-03-26T00:26:21.813