0

I tried using this code:

SET Tmstp=%date:~7,2%%date:~4,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%
FOR %%V IN (%1) DO copy %%V %%V_%Tmstp%.bat && move %%V_%Tmstp% %Target%
echo %0

but it returns the filename in the format filename.bat_timestamp, but I need it as filename_timestamp.bat.

Any help will be great.

Ross Ridge
  • 35,323
  • 6
  • 64
  • 105
  • 1
    for date-time-stamp, I recommend a) another format: `YYYYMMDDhhmmss` because it's easily sortable and b) a [locale independent solution](http://stackoverflow.com/a/18024049/2152082) – Stephan Nov 03 '16 at 07:54

1 Answers1

1

you need modifiers (described in for /?. These modifiers allow you to access each element of a file name (drive, path, name, extension and some other properties) separately:

... DO copy "%%V" "%%~nV_%Tmstp%%%~xV" && move "%%~nV_%Tmstp%%%~xV" "%Target%"

or if you need the full path:

... DO copy "%%~fV" "%%~dpnV_%Tmstp%%%~xV" && move "%%~dpnV_%Tmstp%%%~xV" "%Target%"
Stephan
  • 47,723
  • 10
  • 50
  • 81