Skip to content

Instantly share code, notes, and snippets.

@kiyoto
Last active July 22, 2017 22:05
Show Gist options
  • Save kiyoto/09ecc0dc66333fe1acf7bdd9146c75e0 to your computer and use it in GitHub Desktop.
Save kiyoto/09ecc0dc66333fe1acf7bdd9146c75e0 to your computer and use it in GitHub Desktop.
tidy download directory on windows
# tidy up the ~/Downloads directory
cd C:\Users\me\Downloads
$week_ago = (Get-Date).AddDays(-7)
dir | Select-Object {
$last_access = $_.lastAccessTime
if ($last_access -lt $week_ago) {
$path = "{0:yyyyMM}" -f $last_access
if (! (Test-Path $path)) { mkdir $path }
if ($_.FullName -notmatch "^20\d\d\d\d") { mv $_.FullName $path }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment