Monthly Archives: August 2013

Simple Storing of File Dates and Restoration with PowerShell

All sorts of things mess around with file dates and of concern to me was a number of home videos I transcoded that ended up with new file creation dates that I wanted to retain against the original write time.  We can handle this in Windows with a little PowerShell.  I’ll assume here that all files are in the same path and without their extensions, all files have unique names.

First capture the original creation dates:

dir | Export-CSV originaldates.csv

After your file edits are complete you use the following script (note there is line in there that will swap the extension):

Import-Csv originaldates.csv | `
    ForEach-Object {
        $originalFile = $_.Name
        $newFile = $originalFile.Split(“.”)[0] + “.mp4”
        $oldDate = get-date -date $_.LastWriteTime
        Get-ItemProperty -Path $newFile | ForEach-Object { $_.LastWriteTime = $oldDate }
    }

This post is mostly a reminder for me but might help you out too.  Always backup before changing files and be careful!