1

I am writing a script that copies files to another directory. I wanted to append the date to the end of the file but when I try to use %date% I get the following:

copy c:\mydir\file.zip "c:\temp\file-%date%.zip"

The system cannot find the path specified.

     0 file(s) copied.

if I remove the %date% it copies just fine

Thanks

1 Answer 1

4

Your %date% contains some reserved character(s), e.g. / (forward slash). As %date% strongly depends on user's locale settings, I'd use next locale-independent solution with date in yyyymmdd format:

SETLOCAL EnableExtensions
for /F "delims=" %%G in ('wmic os get LocalDateTime /value^|find "="') do set %%G
copy c:\mydir\file.zip "c:\temp\file-%LocalDateTime:~0,8%.zip"

Resources (required reading, incomplete):

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .