I’m just about at the end of my rope with this!
The other day I posted here, looking for help in creating a batch file (to ZIP then FTP a file) in DOS. I got some great advice, and have written a few files.
Now, however, I have hit a wall! Here’s what I’m looking to do:
-When I run the batch, I need to move a file from one directory to another. -No problem here.
-Then, I need to rename that copy with a unique filename, so the next time I run it it doesn’t just keep overwriting the file over and over again. Some days, I’ll need to run this 4 or 5 times, and I need to keep all previous versions for at least a few days.
I know what I need to do here. I need to capture the date and time from my computer, set it as a variable, then apply it to the file name with the ‘ren’ command (I’ve also seen some examples use ‘xcopy’).
I’ve tried a few hundred different ways, and nothing seems to work! Here’s my latest attempt:
@Echo OFF
TITLE DateName
REM DateName.CMD
REM takes a filename as %1 and renames as %1_YYMMDDHHMM
REM
REM -------------------------------------------------------------
IF %1.==. GoTo USAGE
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP
DATE /T > %CURRDATE%
TIME /T > %CURRTIME%
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k
Echo RENAME %1 %1_%YYYYMMDD%%HHMM%
RENAME %1 %1_%YYYYMMDD%%HHMM%
GoTo END
:USAGE
Echo Usage: DateName filename
Echo Renames filename to filename_YYYYMMDDHHMM
GoTo END
:END
REM
TITLE Command Prompt
…This nightmare doesn’t work though! When I try and run it, it returns:
Bad command or filename
Usage: DateName filename
Renames filename to filename_YYYYMMDDHHMM
Bad command or file name
So, from what I understand:
The first “Bad command” tell sme it won’t even capture the date & time. (And when I simply type “date /t”, DOS does not display the date, instead it returns “Invalid date Enter new date (mm-dd-yy):”).
And I’m not sure if the usage line is supposed to be code or it its supposed to display that text.
I guess the short question is, can anyone please help me with this simple task?