Last active
May 22, 2024 16:43
-
-
Save aravindnc/b6b3dbaa65ff060ff5cf8c906bb40676 to your computer and use it in GitHub Desktop.
Script to organize unsorted files to Year/Month folder. [Powershell]
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
| $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