Created
July 28, 2014 02:39
-
-
Save russellds/27e67ec548e1c2b37e4c to your computer and use it in GitHub Desktop.
Rename pictures to date taken using Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Rename-PictureToDateTaken { | |
param( | |
[string]$Path | |
) | |
$assemblyLoaded = [appdomain]::currentdomain.getassemblies() | | |
where { $_ -match 'System.Drawing' } | |
if( -not $assemblyLoaded ) { | |
Add-Type -AssemblyName System.Drawing | |
} | |
$files = Get-ChildItem -Path $Path | |
foreach( $file in $files ) { | |
$fs = New-Object System.IO.FileStream $file.FullName, 'Open', 'Read' | |
$image = [Drawing.Image]::FromStream($fs, $false, $false) | |
$imageProperty = $image.GetPropertyItem(36867) | |
$fs.Close() | |
$dateTaken = [Text.Encoding]::UTF8.GetString($imageProperty.Value) #-replace ":", "-" -replace " ", "_" | |
$dateTaken = $dateTaken.Substring(0, ($dateTaken.Length - 1)) -replace ":", "-" -replace " ", "_" | |
$newName = $dateTaken + $file.Extension | |
#Start-Sleep -Milliseconds 100 | |
Rename-Item -Path $file.FullName -NewName $newName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment