- extract the photos from their existing folders by doing a search in the Photos folder
- Segregate the photos into different subfolders depending on which camera they came from
- Perform the bulk rename using the new name pattern YYYYMMDD-HHMMSS_cam_#$O (IrfanView)
- Move everything back into their existing folders again.
The piece of PowerShell script that has accomplished this is listed below. I didn’t need to write it in PowerShell; there are plenty of scripting language options in Windows. However I chose PowerShell because of its flexibility and functionality and because I need to learn more about it to use it in the course of my everyday work.
$photonames = Get-ChildItem -Path "D:\users\kahuk_000\Pictures\Photos"So basically this script reads all the filenames in the Photos folder. It goes through each one in turn and checks to see it is a filename then it does a few checks to determine if the filename contains a valid year. With that completed it then extracts the parameters needed to make a valid directory name. It is then a simple matter of looking up the directory name and then moving the photo into that folder.
foreach($filename in $photonames)
{
if ($filename.Attributes -ne "Directory")
{
if ($filename.Length -ge 10)
{
$folderyear = $filename.Name.Substring(0,4)
if ($folderyear -ge 1980)
{
if ($folderyear -le 2014)
{
$foldermonth = $filename.Name.Substring(4,2)
$folderday = $filename.Name.Substring(6,2)
$foldername = $folderyear + "_" + $foldermonth + "_" + $folderday
$foldername
$folderpath = "D:\users\kahuk_000\Pictures\Photos\" + $foldername
if ((Test-Path $folderpath -pathtype container) -eq $true)
{
Move-Item $filename.FullName $folderpath
}
}
}
}
}
}
And that is what scripting is great for, automating day to day tasks and making our lives easier.