This cmd script is giving me a headache. (I inherited it from I don't know whom, and was told to make it work.)
It's a simple version-saver: invoked in Explorer's context menu, it copies the selected file to a folder named "PreviousVersions." It inserts a date/timestamp into the filename.
The weird thing is that on our W2k server it works fine. But on the XP servers, it creates the file with a short filename, i.e., %FN% becomes something like XXXXXX~9. Obviously, we want the long filename.
And, oh yeah, I've tried using "for" to parse for the dot and break things up myself, but my new friends think it's a great idea to use periods as often as they please in a filename.
Any ideas?
It's a simple version-saver: invoked in Explorer's context menu, it copies the selected file to a folder named "PreviousVersions." It inserts a date/timestamp into the filename.
The weird thing is that on our W2k server it works fine. But on the XP servers, it creates the file with a short filename, i.e., %FN% becomes something like XXXXXX~9. Obviously, we want the long filename.
And, oh yeah, I've tried using "for" to parse for the dot and break things up myself, but my new friends think it's a great idea to use periods as often as they please in a filename.
Any ideas?
Code:
@echo off
cd /d %~dp1
if exist "%~dp1\PreviousVersions" goto :COPYFILE
md "%~p1\PreviousVersions"
:COPYFILE
set FN=%~n1
set XN=%~x1
for /f "tokens=1-6 delims=/: " %%a in ("%~t1") do (
set DT=%%c%%a%%b
set Hours=%%d
set Minutes=%%e
set AMPM=%%f)
set DT=%DT:~0,8%
set Minutes=%Minutes:~0,2%
set Hours=%Hours:~0,2%
if %Hours% LSS 12 if /I "%AMPM%"=="PM" set /A Hours=%Hours%+12
if %Hours% EQU 12 if /I "%AMPM%"=="AM" set Hours=00
copy "%1" ".\PreviousVersions\%FN%_%DT%_%Hours%%Minutes%%XN%"
attrib +R ".\PreviousVersions\%FN%_%DT%_%Hours%%Minutes%%XN%"
:END