- 1 year ago
Windows Command Line - Changing a file modified timestamp to an earlier datetime
In Windows Command Prompt, you can change a file's modified timestamp to an earlier datetime using the copy
command in combination with the echo
command. The echo
command allows you to create a new file with a specific content, and by copying this file over the original file, you can modify its modified timestamp. Here's how to do it:
Create a text file with the desired datetime: Open the Command Prompt, and use the
echo
command to create a text file containing the desired datetime in the format "MM-DD-YYYY HH:MM:SS":bashecho 01-01-2023 10:30:00 > timestamp.txt
Replace "01-01-2023 10:30:00" with the datetime you want to set for the file.
Copy the timestamp from the text file to the target file: Now, use the
copy
command to copy the content oftimestamp.txt
to the target file. This action will update the modified timestamp of the target file to the datetime specified intimestamp.txt
:bashcopy /B /Y timestamp.txt + targetfile.txt
Replace
targetfile.txt
with the name of the file whose timestamp you want to change.Delete the temporary timestamp file: You can delete the temporary
timestamp.txt
file using thedel
command:bashdel timestamp.txt
After completing these steps, the modified timestamp of the target file will be changed to the earlier datetime specified in the
timestamp.txt
file. Please note that this method modifies the file's timestamp but does not change its content.
Keep in mind that modifying timestamps in this way might not be appropriate for all situations and could affect the integrity of the file's metadata. Additionally, if you are dealing with critical system files or protected directories, Windows might prevent you from modifying the timestamps. Use this method responsibly and only for legitimate purposes.