Skip to content

Instantly share code, notes, and snippets.

@toksikk
Created July 11, 2022 16:56
Show Gist options
  • Save toksikk/5a37845697b02c0b2e412ec03d0cee4d to your computer and use it in GitHub Desktop.
Save toksikk/5a37845697b02c0b2e412ec03d0cee4d to your computer and use it in GitHub Desktop.
I had a tool that did not write EXIF data to jpg files so I wrote this small Powershell script to use the file names that were conveniently creation dates in unix millisecond timestamps.
Add-Type -AssemblyName System.Drawing
$imageSourcePath = Get-Location
$files = Get-ChildItem -Path $imageSourcePath -filter *.jpg
$numFiles = $files.Count
[Int32]$counter = 0
foreach ($file in $files) {
$takenDateUNIXMilli = $file.BaseName
$takenDate = ((Get-Date 01.01.1970) + ([System.TimeSpan]::frommilliseconds($takenDateUNIXMilli)))
$counter++
Write-Progress "$numFiles image files." -PercentComplete (100 * $counter / $numFiles)
$file.CreationTime = $takenDate
$file.LastWriteTime = $takenDate
}
Write-Output "Fixed CreationTime and LastWriteTime for $numFiles files from $imageSourcePath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment