Technology, life, programming, travel and money.

Backup / restore of last modified and created file time attributes on Windows

Last month I found that I needed to be able to backup and restore the last modified and created file times of a load of files in Windows XP. This is probably a bit of an obscure thing to need to do so naturally I couldn’t find any existing tools to do it.

I’ve therefore made a Perl script to allow this to be done. Just so you are clear, this isn’t backing up the files, it is backing up the last modified and created file time attributes.

This allows changes to be made to the files whilst keeping these attributes intact. In theory Perl’s utime function should allow me to change these attributes. However on my Windows XP machine it just didn’t work. I’ve therefore used the rather excellent nircmd tool to handle the file attribute modifications. You’ll need to download it and modify backupLastModified.pl to point to it.

Usage is simple:

perl backupLastModified.pl c:\yourdir -backup
perl backupLastModified.pl c:\yourdir -restore

Make sure you do a test of this script before you use it for real. It has only ever been tested on one machine.

  1. Download backupLastModified.zip
  2. View backupLastModified.pl

This script will create a file ‘backuplist.txt’ in the directory that you pass in as the first argument. If you run -backup multiple times then any new files will be appended to the backuplist.txt. The stored last modified / created times of any existing files will be preserved.


Reader Feedback

2 Responses to “Backup / restore of last modified and created file time attributes on Windows”

  1. Kitty says:

    This is exactly I was looking for.

    Thank you very much :)

  2. Kitty says:

    Just to add a note:

    I have filenames containing the comma character, so I switched the separator to one which would be illegal in any file name (I used pipe |), and altered the split statements to match.

    Don’t forget to escape the pipe in the split statement ;)

    It was all certainly a lot easier than installing Cygwin and knocking up a Bash script!

Leave a Reply

Do NOT fill this !