Created
June 15, 2024 00:06
-
-
Save chrisbrownie/6143a61da556ba606ec7c250e280df73 to your computer and use it in GitHub Desktop.
Clean up images in a folder, moving them to subfolders named YYYY-MM based on the image's creation date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$screenshotsDir = "$($env:userprofile)\OneDrive\Pictures\Screenshots" | |
$fileType = "png" | |
$images = Get-ChildItem -Path $screenshotsDir -filter "*.$fileType" | |
for ($i=0; $i -lt $images.Length; $i++) { | |
$monthYearString = $images[$i].CreationTime.Year.ToString() + "-" + $images[$i].CreationTime.Month.ToString().PadLeft(2,"0") | |
$folder = Join-Path $screenshotsDir $monthYearString | |
if (-not (Test-Path -Path $folder -PathType Container)) { | |
# Creating path | |
New-Item -Path $folder -ItemType Directory | |
} | |
Move-Item $images[$i].FullName $folder | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or this one for Dropbox\Camera Uploads: