Skip to content

Instantly share code, notes, and snippets.

@aravindnc
Last active May 22, 2024 16:43
Show Gist options
  • Select an option

  • Save aravindnc/b6b3dbaa65ff060ff5cf8c906bb40676 to your computer and use it in GitHub Desktop.

Select an option

Save aravindnc/b6b3dbaa65ff060ff5cf8c906bb40676 to your computer and use it in GitHub Desktop.
Script to organize unsorted files to Year/Month folder. [Powershell]
$sourceDir = ".\"
$destinationDir = ".\"
Get-ChildItem -Path $sourceDir | ForEach-Object {
if ($_.PSIsContainer -eq $false) {
# Use "MMM-dd" for Jan-01 like format
$dateModified = $_.LastWriteTime.ToString("yyyy/MM")
$destinationPath = Join-Path -Path $destinationDir -ChildPath $dateModified
if (-not (Test-Path -Path $destinationPath)) {
New-Item -ItemType Directory -Force -Path $destinationPath
}
Move-Item -Path $_.FullName -Destination $destinationPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment