Organize Camera Photos and Videos Using PowerShell

I was searching for a quick and easy way to organize the contents of my cameras SD card when I transfer the files off to my computer.  It would be great to have the time to organize all the photos per event (Grandpa’s Birthday, Birth of Child Number 2, etc), but this never works.  I always put off that task and I end up with a monster SD card with an unmanageable amount of photos and videos.  The problem is compounded by the additional directories that the camera uses for its organization.

Well I found a simple PowerShell script that did this online (see here, a blog post from Kim Oppalfens), but there were some problems.

  1. The directories were too granular (one directory for each day of photos).
  2. It only handled photos.
  3. My camera doesn’t embed the date in the jpg the way that this script was expecting, resulting in some null ref errors when running the script.

So I wrote my own which I’ll share with you here, you can also download a text version here.

$PhotosDirectory="d:\Photos & Movies"

Function CopyFiles([System.IO.FileInfo[]]$Files)
    $currentCount = 0
    $percent = 0;

    Write-Host "  0% Complete"
    foreach ($file in $Files)
        if ($currentCount -gt ($Files.Length / 10))
            $percent += 10
            $percentString = $percent.ToString().PadLeft(3, ' ')
            Write-Host "$percentString% Complete"
            $currentCount = 0

        $year = $file.CreationTime.Year.ToString()
        $month = $file.CreationTime.Month.ToString().PadLeft(2, '0')
        $monthName = $file.CreationTime.ToString("MMMM") # <-- Month Name

        $TargetDirectory = "$year\$month - $monthName"
        $TargetPath = "$PhotosDirectory\$TargetDirectory"

        if (!(test-path $targetpath))
            new-item $targetpath -type directory >> log.txt
        xcopy /y $file.fullname "$targetpath" >> log.txt
    Write-Host "100% Complete"

Write-Host "Copying JPG's"
$files = Get-ChildItem -recurse -filter *.jpg
Write-Host "Copying MOV's"
$files = Get-ChildItem -recurse -filter *.mov

Couple key points

  1. Copy contents of above script and past into a new file.  I named mine Photos.ps1 and put in my C:\Users\<user name>\Documents\WindowsPowerShell directory.  The name doesn’t matter, but the extension of ps1 does.
  2. Launch PowerShell.
  3. Insert you SD card, and navigate to the directory where your photos or stored.  I did this by inserting the SD card into my reader, but the usb cord worked as well.
  4. Run your ps1 file by typing the full path and file name.

The result is a well organized directory of your digital photos and videos.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

One Comment

Leave Comment