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,
But I obviously want it to be
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.