Skip to content

Instantly share code, notes, and snippets.

@craibuc
Created January 19, 2020 19:51
Show Gist options
  • Select an option

  • Save craibuc/fdc4ac44516988cefd612b5d6212a1af to your computer and use it in GitHub Desktop.

Select an option

Save craibuc/fdc4ac44516988cefd612b5d6212a1af to your computer and use it in GitHub Desktop.
Organize media files by month and year
# 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