Skip to content

Instantly share code, notes, and snippets.

Last active March 21, 2021 08:44
What would you like to do?
Move your camera roll pictures in folders, i've liked year / year-month with month having leading 0 (originally at
$TagLib = "C:\Program Files\PackageManagement\NuGet\Packages\TagLibSharp.2.2.0\lib\netstandard2.0\TagLibSharp.dll"
Add-Type -Path $TagLib
# Get the files which should be moved, without folders
$files = Get-ChildItem 'X:\OneDrive\Pictures' -Recurse | Where-Object { !$_.PSIsContainer }
# List Files which will be moved
# Target Filder where files should be moved to. The script will automatically create a folder for the year and month.
$targetPath = 'X:\OneDrive\Photos'
foreach ($file in $files) {
$tag = [TagLib.File]::Create($file)
# Get year and Month of the file
if ($tag.ImageTag.DateTime) {
$year = $tag.ImageTag.DateTime.Year.ToString()
# add 0 prefix to month
$month = $tag.ImageTag.DateTime.Month.ToString("00")
elseif ($tag.Tag.DateTime) {
$year = $tag.Tag.DateTime.Year.ToString()
# add 0 prefix to month
$month = $tag.Tag.DateTime.Month.ToString("00")
else {
# I used LastWriteTime since this are synced files and the creation day will be the date when it was synced
$year = $file.LastWriteTime.Year.ToString()
# add 0 prefix to month
$month = $file.LastWriteTime.Month.ToString("00")
# Out FileName, year and month
# Set Directory Path , change as wanted
$Directory = $targetPath + "\" + $year + "\" + $year + "-" + $month
# Create directory if it doesn't exists
if (!(Test-Path $Directory)) {
New-Item $directory -type directory
# Move File to new location, remove -Force if you might have files with the same name, i've used it since i knew that duplicates are ok to overwrite
$file | Move-Item -Destination $Directory -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment