Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. $DaysBack = 14
  2. $ArchiveYears = 2
  3. [switch]$Timestamp = $true
  4. [switch]$WhatIf = $false
  5. $Types=(".png",".jpg",".gif",".mp4")
  6.  
  7. If($env:COMPUTERNAME -eq "ZEUS"){
  8. $FolderToOrganize = 'D:\Chris\Dropbox\Camera Uploads'
  9. $ArchiveLocation = 'D:\Chris\Dropbox\Archive\Photos'
  10. }ElseIf($env:COMPUTERNAME -eq "NCC1701"){
  11. $FolderToOrganize = 'C:\Users\Christopher\Dropbox\Camera Uploads'
  12. $ArchiveLocation = 'C:\Users\Christopher\Dropbox\Archive\Photos'
  13. }Else{
  14. $ErrorActionPreference = "Stop"
  15. Write-Error "we're boned. go look at the script."
  16. #That's code for you're running it on the wrong system and too lazy to deal with multiple paths.
  17. }
  18.  
  19.  
  20.  
  21. If( $FolderToOrganize ) {
  22. $TopLevel = Get-Item ( $FolderToOrganize )
  23. }Else{
  24. $TopLevel = Get-Item ( Get-Location )
  25. }
  26. $DateCutoff = (Get-Date).AddDays($DaysBack * -1)
  27. $ArchiveCutoff = (Get-Date 1/1).AddYears(($ArchiveYears-1) * -1)
  28.  
  29. If( $Timestamp ){
  30. $FilesetToArchive = Get-ChildItem -Recurse -Path $FolderToOrganize | Where {$_.LastWriteTime -le "$ArchiveCutoff" -and $_.Extension -in $Types.Split(",") -and $_.Directory -notmatch "Shares"}
  31. $FilesetToOrganize = Get-ChildItem -Path $FolderToOrganize | Where {$_.LastWriteTime -le "$DateCutoff" -and $_.Extension -in $Types.Split(",") -and $_.Directory -notmatch "Shares"}
  32. }Else {
  33. #Fuckoff
  34. }
  35.  
  36. $FilesetToOrganize | ForEach-Object {
  37. $FileYear = ($_.LastWriteTime).Year
  38. $FileMonth = ($_.LastWriteTime).Month
  39. If( !(Test-Path (Join-Path $FileYear $FileMonth)) ){
  40. New-Item -Name (Join-Path $FileYear $FileMonth) -ItemType Directory
  41. }
  42. $DestDir = (Join-Path $FileYear $FileMonth)
  43. Write-Output "Moving $_ to $DestDir"
  44. Move-Item $_ $DestDir
  45. }
  46.  
  47. If($env:COMPUTERNAME -eq "ZEUS"){
  48. $FilesetToArchive | ForEach-Object {
  49. $FileYear = ($_.LastWriteTime).Year
  50. $FileMonth = ($_.LastWriteTime).Month
  51. If( !(Test-Path (Join-Path $ArchiveLocation (Join-Path $FileYear $FileMonth))) ){
  52. New-Item -Path $ArchiveLocation -Name (Join-Path $FileYear $FileMonth) -ItemType Directory
  53. }
  54. $DestDir = (Join-Path $ArchiveLocation (Join-Path $FileYear $FileMonth))
  55. Write-Output "Archiving $_ to $DestDir"
  56. Write-Output ("From path: "+$_.Directory)
  57. Move-Item $_.FullName $DestDir
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement