Inside a batch-file the %
characters require doubling:
@For /R "C:\Folder" %%G In (*.tif)Do @For /F "Tokens=1-5Delims=:-\/. " %%H In ("%%~tG")Do @Ren "%%G" "%%~H_%%~I%%~J_%%~K%%~L_%%~nxG"
Although, in a batch file, I'd suggest that you do not use a single line, (limiting line lengths within 80
characters to match the default cmd.exe window width and to assist reading):
@For /R "C:\Folder" %%G In (*.tif)Do @For /F "Tokens=1-5Delims=:-\/. " %%H In (
"%%~tG")Do @Ren "%%G" "%%~H_%%~I%%~J_%%~K%%~L_%%~nxG"
BTW, your initial cmd example could have looked more like this:
For /R "C:\Folder" %G In (*.tif)Do @For /F "Tokens=1-5Delims=:-\/. " %H In ("%~tG")Do @Ren "%G" "%~H_%~I%~J_%~K%~L_%~nxG"
You had some unnecessary parentheses and an unused token and could have merged the name and extension into a single modifier instead of two. You could also have removed the unnecessary expansion and modifiers from the filename to be renamed.
[Edit /]
BTW, you'll note that I didn't answer your second question, because the
%~t
modifier doesn't output seconds and milliseconds,
(you could therefore probably remove the .
delimiter), so you cannot retrieve it from that code. You would therefore need to use an alternative method, and this site does not provide a free code writing service, so you'd need to post a new question once you have that code. Also problems/issues should be limited to only one per post.