Created
January 20, 2017 22:15
-
-
Save tubaterry/7bb18ae4698c8668ca9d1e885b7434eb to your computer and use it in GitHub Desktop.
Quick organizer script for keeping my camera uploads off of my low storage volume devices
This file contains 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
$DaysBack = 14 | |
$ArchiveYears = 2 | |
[switch]$Timestamp = $true | |
[switch]$WhatIf = $false | |
$Types=(".png",".jpg",".gif",".mp4") | |
If($env:COMPUTERNAME -eq "ZEUS"){ | |
$FolderToOrganize = 'D:\Chris\Dropbox\Camera Uploads' | |
$ArchiveLocation = 'D:\Chris\Dropbox\Archive\Photos' | |
}ElseIf($env:COMPUTERNAME -eq "NCC1701"){ | |
$FolderToOrganize = 'C:\Users\Christopher\Dropbox\Camera Uploads' | |
$ArchiveLocation = 'C:\Users\Christopher\Dropbox\Archive\Photos' | |
}Else{ | |
$ErrorActionPreference = "Stop" | |
Write-Error "we're boned. go look at the script." | |
#That's code for you're running it on the wrong system and too lazy to deal with multiple paths. | |
} | |
If( $FolderToOrganize ) { | |
$TopLevel = Get-Item ( $FolderToOrganize ) | |
}Else{ | |
$TopLevel = Get-Item ( Get-Location ) | |
} | |
$DateCutoff = (Get-Date).AddDays($DaysBack * -1) | |
$ArchiveCutoff = (Get-Date 1/1).AddYears(($ArchiveYears-1) * -1) | |
If( $Timestamp ){ | |
$FilesetToArchive = Get-ChildItem -Recurse -Path $FolderToOrganize | Where {$_.LastWriteTime -le "$ArchiveCutoff" -and $_.Extension -in $Types.Split(",") -and $_.Directory -notmatch "Shares"} | |
$FilesetToOrganize = Get-ChildItem -Path $FolderToOrganize | Where {$_.LastWriteTime -le "$DateCutoff" -and $_.Extension -in $Types.Split(",") -and $_.Directory -notmatch "Shares"} | |
}Else { | |
#Fuckoff | |
} | |
$FilesetToOrganize | ForEach-Object { | |
$FileYear = ($_.LastWriteTime).Year | |
$FileMonth = ($_.LastWriteTime).Month | |
If( !(Test-Path (Join-Path $FileYear $FileMonth)) ){ | |
New-Item -Name (Join-Path $FileYear $FileMonth) -ItemType Directory | |
} | |
$DestDir = (Join-Path $FileYear $FileMonth) | |
Write-Output "Moving $_ to $DestDir" | |
Move-Item $_ $DestDir | |
} | |
If($env:COMPUTERNAME -eq "ZEUS"){ | |
$FilesetToArchive | ForEach-Object { | |
$FileYear = ($_.LastWriteTime).Year | |
$FileMonth = ($_.LastWriteTime).Month | |
If( !(Test-Path (Join-Path $ArchiveLocation (Join-Path $FileYear $FileMonth))) ){ | |
New-Item -Path $ArchiveLocation -Name (Join-Path $FileYear $FileMonth) -ItemType Directory | |
} | |
$DestDir = (Join-Path $ArchiveLocation (Join-Path $FileYear $FileMonth)) | |
Write-Output "Archiving $_ to $DestDir" | |
Write-Output ("From path: "+$_.Directory) | |
Move-Item $_.FullName $DestDir | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment