Can a batch file change the system date; save file with attributes; change date back to current date?

Edoctoor picture Edoctoor · Sep 8, 2010 · Viewed 12.6k times · Source

Can a batch file change the system date; save file with attributes; change date back to current date?

Goal to save MYFILE.TXT with the date of 01-01-2010

using Batch commands.

I have tried to set date=01-01-2010

and then save the file, but it didn't work.

Is this impossible?

@echo off
rem to Run this Batch file as administrator

date 01-01-2010
echo %date%
pause
echo Hello World > test.txt

date 09-08-2010

echo %date%
pause

goto :eof

Note: If we didn't "Run as Administrator" It creates an error message of "A required privilege is not held by the client."

Answer

Jack Kelly picture Jack Kelly · Sep 8, 2010

Your best bet is to probably grab touch from GNUWin32 and use that to change the timestamps. Doing this by changing the system date is like using a sledgehammer to crack a nut.