THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Merrill Aldrich

Technical content about Microsoft data technologies. All opinions expressed are purely my own and do not reflect positions of my employer or associates.

Organize Those Holiday Photos with PowerShell

My parents are here visiting with us for a little holiday vacation – and my mother is getting to be more and more computer savvy. She has an iPhone and a digital camera, and loves to take pictures. In fact, today she has almost 6,000 photos between the two devices! She takes so many photos that the media on the devices fills up, and then she goes back through the old photos deleting some just to make space. But moving the files to a computer or a DVD is still beyond her reach, so when she comes to visit there is usually a little family time burning all the photos that she has taken, since the last time we were together, to disks.

There are so many pictures and movies this time I created a PowerShell snippet to organize them into folders by year and month. In case anyone else needs to organize a giant folder full of files by date, I thought I would share:

Set-Location '\\Machine\MerrillAldrich\Mom''s Pictures'

get-childitem -Filter *.jpg | foreach {
    $y = get-date $_.creationTime -Format 'yyyy' 
    $m = get-date $_.creationTime -Format 'MM'
    $folder = join-path $y $m
    if ( ! ( test-path $folder ) ) {
        mkdir $folder 
    move-item $_ $folder

In this case we put the photos onto my MacBook Pro, but PowerShell is so handy it was worth sharing the folder out on the network to run this little script from my ThinkPad.

Happy New Year!

Published Sunday, January 5, 2014 9:11 AM by merrillaldrich



ALZDBA said:

Nice script, Merrill.

It shows how you might do it the easy way.

However, it lacks to use the picture property "date taken", which is available using .Net properties in System.Drawing.

The script in this reference uses this property information, which will even make your photo library more accurate.

February 22, 2014 10:52 AM
New Comments to this post are disabled

This Blog


Privacy Statement