Blog Post

Photo cataloguer

,

If you are anything like me, by know you will have a few thousand digital images spread across multiple directories and heaven knows how many of those are duplicates!

Here’s a little powershell script I use to try and keep them in order,  it recursively scans a directory (hardcoded to D:\photodrop) and interrogates any .jpg file for its taken date and time and moves the file to an appropriately named folder /CCYY/MM/DD.

Naturally, I cannot be held responsible if your precious memories get lost by using this script 😉

Let me know how you get on…

[reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")

#http://archive.msdn.microsoft.com/PowerShellPack

function CreatePath ($folderPath){

    $Path1 = $folderpath.Split("\")
    $BuildPath = ""
    for($x=0;$x -lt $Path1.count;$x+=1){
        $BuildPath = $BuildPath += $Path1[$x] +"\"
        if($objFSO.FolderExists($BuildPath) -eq $FALSE){
            $objFSO.CreateFolder($BuildPath) | Out-Null
         }
    }

}

function MakeString {
    $s="" ;
    $x = $args[0]
    for ($i=0 ; $i -le $args[0].value.length; $i ++)
    {
        $s = $s+ [char]$args[0].value[$i]
    }
    return $s
}
$objFSO = New-Object -ComObject Scripting.FileSystemObject
           
$LastFilePath=""
foreach($File in Get-ChildItem -Path D:\PhotoDrop -Filter *.jpg -Recurse ){
    $ImgBlob = New-Object -TypeName system.drawing.bitmap -ArgumentList $File.FullName
    $Date=""
    $Date = MakeString($ImgBlob.GetPropertyItem(36867))
    $ImgBlob.Dispose()
   
    try {
        $Dir = $Date.Substring(0,10)
        $Dir = $Dir.Replace(":","\")
        $folderPath = "D:\Photos\"+$Dir
        #check to see if it is missing
        if($LastFilePath -ne $folderPath){
            CreatePath $folderPath
            $LastFilePath = $folderPath
        }
       
        $NewFileName = $folderPath+"\"+$File.Name
        if($objFSO.FileExists($NewFileName) -eq $FALSE){
            $File.MoveTo($NewFileName)
        }
       
           
    }
    catch{
        $err=$Error[0]
         $err
 

    }
}

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating