Advertisement
1976ddc

CleanSandstormMods.ps1

Dec 30th, 2020 (edited)
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Instructions: Change the path on the line below to your Insurgency Sandstorm modio folder (no slash on end).Then save and run script.
  2. $insmodio='C:\Program Files (x86)\Steam\steamapps\common\sandstorm\Insurgency\Mods\modio'
  3.  
  4. #Script - dont modify anything from here down, unless you know what you're doing
  5. #First check that the path is exists or is an Insurgency modio directory, nag if something is wrong
  6. [String]$exist=Test-Path $insmodio
  7. if ($insmodio -notlike '*sandstorm\Insurgency\Mods\modio*' -or $exist -eq 'False') {
  8.     Write-Host -ForegroundColor Red "Incorrect path->" $insmodio
  9.     Write-Host -ForegroundColor Cyan "Above Path does not exist or is not an Insurgency Sandstorm Modio folder!"
  10.     Write-Host -ForegroundColor Cyan "Edit line 2 of this script to point to your Insurgency Sandstorm Modio folder"
  11.     Read-Host -Prompt "Exiting! Press press enter to quit"
  12.     exit
  13. }
  14.  
  15. #Variable declarations / modio folder size check
  16. $ogsize=((Get-ChildItem $insmodio -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum)
  17. $ogsizegb="{0:N2} GB" -f (($ogsize) / 1GB)
  18. $insmods=Get-ChildItem $insmodio -Directory
  19. $deletes=@()
  20. $track=0
  21.  
  22. #Processing and reporting on modio folder/don't touch newest folder and capture deletes for processing
  23. write-host  -ForegroundColor Cyan "Processing mod folders in" $insmodio
  24. write-host  -ForegroundColor Cyan "Insurgency Sandstorm Mod folder size:" $ogsizegb
  25. foreach ($mod in $insmods) {
  26.     $modpath=$insmodio+'\'+$mod
  27.     $modchildren=Get-ChildItem $modpath -Directory | Sort-Object -Descending -Property CreationTime
  28.     $count=0
  29.     foreach ($submoddir in $modchildren) {$count=$count+1}
  30.     If ($count -gt 1) {
  31.         $count=0
  32.         $track=1
  33.         write-host "********************************************"
  34.         write-host $modpath "has multiple sub-directories and the following action will be taken:"
  35.         foreach ($submoddir in $modchildren) {
  36.             $submodpath=$modpath+'\'+$submoddir
  37.             $submodpathprop=Get-Item $submodpath
  38.             $count=$count+1
  39.             If ($count -eq 1) {
  40.                 write-host  -ForegroundColor Green $submoddir "created" $submodpathprop.CreationTime "is the newest and is being kept."
  41.             }
  42.             Else {
  43.                 write-host -ForegroundColor Red  $submoddir "created" $submodpathprop.CreationTime "is older and being deleted."
  44.                 $deletes=$deletes+$submodpath
  45.             }
  46.         }
  47.      }
  48. }
  49. write-host "********************************************"
  50.  
  51. #In the event script run 2x or no folders require processing
  52. If ($track -eq 0) {
  53.     Write-host -ForegroundColor Green "No old versions of mods were found requiring deletion, quitting."
  54.     Read-Host -Prompt "Press press enter to quit"
  55.     exit
  56. }
  57. #"{0:N2} GB" -f ((Get-ChildItem $insmodio -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB)
  58.  
  59. #confirmation loop, if there are deletes user can review report before deleting
  60. $confirmation= Read-Host "Are you sure you want to delete all folders listed in red above? [y/n]"
  61. while ($confirmation -ne 'y') {
  62.     if ($confirmation -eq 'n') {exit}
  63.     $confirmation= Read-Host "Are you sure you want to delete all folders listed in red above? [y/n]"
  64. }
  65.  
  66. #Deletion code, some checking if folder in fact deleted and warns if it has not been
  67. foreach ($delete in $deletes) {
  68.     Get-ChildItem -Path $delete -Recurse | Remove-Item -force -recurse -ErrorAction SilentlyContinue
  69.     Remove-Item $delete -Force
  70.     [String]$exists=Test-Path $delete
  71.     if ($exists -eq 'True') {write-host -ForegroundColor Red "Unable to delete folder, perhaps re-run script as administator or manually delete:" $delete}
  72.     if ($exists -eq 'False') {write-host -ForegroundColor Green "Successfully deleted:" $delete}
  73. }
  74.  
  75. #final modio size savings check and report
  76. $newsize=((Get-ChildItem $insmodio -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum)
  77. $newsizegb="{0:N2} GB" -f (($newsize) / 1GB)
  78. $removedspace="{0:N2} GB" -f (($ogsize - $newsize) / 1GB)
  79. write-host "********************************************"
  80. Write-Host "Modio folder Size before deletion" $ogsizegb
  81. Write-Host "Modio folder Size after deletion" $newsizegb
  82. Write-Host -ForegroundColor Green "Saved Space" $removedspace
  83. Read-Host -Prompt "Press enter to quit"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement