Sportsguy
asked on
Time Date stamp using DOS Batch file via CMD on WINNT
Is there a way in a bat file to add a time stamp to a file copy. For example,
copy \\Apps1\FTPFile\FileUpload .zip \\Apps2\UploadFiles\FileUp load(time stamp).zip
I am trying to use this command:
for /F "tokens=2,3,4 delims=/ " %%i in ("%date%") do set d=%%k%%i%%j
for /F "tokens=1,2,3 delims=:. " %%i in ("%time%") do set t=%%i%%j%%k
echo %d%-%t%
copy D:\Data\Comm\BSIQ.txt D:\Plugins\Worldmt940\BSIQ %d%%t%.txt
It only reurns the file name with no time date stamp.
The operating system is WINNT
Thanks.
copy \\Apps1\FTPFile\FileUpload
I am trying to use this command:
for /F "tokens=2,3,4 delims=/ " %%i in ("%date%") do set d=%%k%%i%%j
for /F "tokens=1,2,3 delims=:. " %%i in ("%time%") do set t=%%i%%j%%k
echo %d%-%t%
copy D:\Data\Comm\BSIQ.txt D:\Plugins\Worldmt940\BSIQ
It only reurns the file name with no time date stamp.
The operating system is WINNT
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ok, so ignore my comments about the space... Didn't realise the fonts used here made single spaces nearly invisible in code :)
ASKER
Thanks Billious! Worked like a charm
ASKER
Thanks for the explaination Jherad
The syntax you gave would work fine on 2000 but not NT4 as the date/time are not environment variables within NT4.
One caveat to this is you need a space after the / delimiter or it won't skip the day, thus:
for /f "tokens=2-4 delims=/ " %%i in ("%DATE%") do set d=%%k%%i%%j
your line for the time looks fine unaltered.
With NT4, as billious has commented you need to use TIME /T and DATE /T to output the date/time, surrounded by single quotes instead of doubles.
-Jherad