Archive for 13th April 2019

Organizing a family photo collection using PowerShell, part 2

Just to recap from last month’s post, I have been given the chore of… Organizing a photo collection.

The files were on several computers and backups, so PowerShell on Windows 10 became the main vehicle with which I would try to bring this beast under control.

Plan for organizing a photo collection

  1. Bring photos together from all sources into one place
  2. Remove duplicate photos
  3. Organize photos by month and year

Step 3

Here is the PowerShell script that I used to organize the photos into folders by month and year. (WARNING: Any time you set up any kind of automated file process, make sure that you have backups.)

function fmove($SourceDir,$DestinationDir)
{
	$files = Get-ChildItem $SourceDir
	foreach ($file in $files) 
	{
		$Directory = $DestinationDir + "" + $file.LastWriteTime.Date.ToString('yyyy') + " " + $file.LastWriteTime.Date.ToString('MM')
		if (!(Test-Path $Directory))
		{
			New-Item $directory -type directory -Verbose
		}
		Move-Item $file.fullname $Directory -Verbose
	}
}
 
fmove -SourceDir "C:\Users\Me\Desktop\IntermediateDestination\" -DestinationDir "C:\Users\Me\Desktop\FinalDestination\"

There is not much going on here. The scripts iterates through all files in the source directory. For each individual file, there is a check to see if a folder exists with the last write year and month, creating it if necessary. And finally, the individual file is moved to that folder.

Once this script finishes, you will have a bunch of folders with files in them corresponding (roughly) to their date. However, please keep in mind that this might not be accurate if the files have been processed by other software.

BTW, Happy Birthday to the two dollar bill, issued on this date in 1976 to correspond with Thomas Jefferson’s birthday.