Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement