Created
January 19, 2020 19:51
-
-
Save craibuc/fdc4ac44516988cefd612b5d6212a1af to your computer and use it in GitHub Desktop.
Organize media files by month and year
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
| # get all media files in the curret directory | |
| Get-ChildItem * -File -Include *.jpg, *.png, *.mp4 | | |
| # sort them by date created (not necessary) | |
| Sort-Object CreationTime | | |
| # process each file | |
| ForEach-Object { | |
| Write-Debug $_.Name | |
| # year and month of file's creation date | |
| $yyyymm = $_.CreationTime.ToString('yyyy-MM') | |
| # create directory if necessary | |
| New-Item -Type Directory $yyyymm -Force | |
| # move file to directory | |
| Move-Item $_.Name -Destination ".\$yyyymm" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment