Skip to content

Instantly share code, notes, and snippets.

@greatb
Last active March 1, 2022 01:00
Show Gist options
  • Save greatb/75e035639eeb38dc286020626e1f5ef5 to your computer and use it in GitHub Desktop.
Save greatb/75e035639eeb38dc286020626e1f5ef5 to your computer and use it in GitHub Desktop.
PS script to group the files by created year-month
$SourceFolder = "E:\Sorce"
$outputDir = "e:\Photos-Grouped"
$files = Get-ChildItem -Path $SourceFolder -Recurse | Where-Object {$_.PSIsContainer -eq $false}
foreach ($file in get-ChildItem $files) {
$toDir = Join-Path $outputDir $file.lastwritetime.toString("yyyy\\yyyy-MM")
$toFile = Join-Path $toDir $file.name
if(!(Test-Path $toDir))
{
New-Item -Path $toDir -ItemType Directory -Force | Out-Null
}
Echo $toFile
Copy-Item -Path $file.FullName -Destination $toFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment