Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Instructions: Change the path on the line below to your Insurgency Sandstorm modio folder (no slash on end).Then save and run script.
- $insmodio='C:\Program Files (x86)\Steam\steamapps\common\sandstorm\Insurgency\Mods\modio'
- #Script - dont modify anything from here down, unless you know what you're doing
- #First check that the path is exists or is an Insurgency modio directory, nag if something is wrong
- [String]$exist=Test-Path $insmodio
- if ($insmodio -notlike '*sandstorm\Insurgency\Mods\modio*' -or $exist -eq 'False') {
- Write-Host -ForegroundColor Red "Incorrect path->" $insmodio
- Write-Host -ForegroundColor Cyan "Above Path does not exist or is not an Insurgency Sandstorm Modio folder!"
- Write-Host -ForegroundColor Cyan "Edit line 2 of this script to point to your Insurgency Sandstorm Modio folder"
- Read-Host -Prompt "Exiting! Press press enter to quit"
- exit
- }
- #Variable declarations / modio folder size check
- $ogsize=((Get-ChildItem $insmodio -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum)
- $ogsizegb="{0:N2} GB" -f (($ogsize) / 1GB)
- $insmods=Get-ChildItem $insmodio -Directory
- $deletes=@()
- $track=0
- #Processing and reporting on modio folder/don't touch newest folder and capture deletes for processing
- write-host -ForegroundColor Cyan "Processing mod folders in" $insmodio
- write-host -ForegroundColor Cyan "Insurgency Sandstorm Mod folder size:" $ogsizegb
- foreach ($mod in $insmods) {
- $modpath=$insmodio+'\'+$mod
- $modchildren=Get-ChildItem $modpath -Directory | Sort-Object -Descending -Property CreationTime
- $count=0
- foreach ($submoddir in $modchildren) {$count=$count+1}
- If ($count -gt 1) {
- $count=0
- $track=1
- write-host "********************************************"
- write-host $modpath "has multiple sub-directories and the following action will be taken:"
- foreach ($submoddir in $modchildren) {
- $submodpath=$modpath+'\'+$submoddir
- $submodpathprop=Get-Item $submodpath
- $count=$count+1
- If ($count -eq 1) {
- write-host -ForegroundColor Green $submoddir "created" $submodpathprop.CreationTime "is the newest and is being kept."
- }
- Else {
- write-host -ForegroundColor Red $submoddir "created" $submodpathprop.CreationTime "is older and being deleted."
- $deletes=$deletes+$submodpath
- }
- }
- }
- }
- write-host "********************************************"
- #In the event script run 2x or no folders require processing
- If ($track -eq 0) {
- Write-host -ForegroundColor Green "No old versions of mods were found requiring deletion, quitting."
- Read-Host -Prompt "Press press enter to quit"
- exit
- }
- #"{0:N2} GB" -f ((Get-ChildItem $insmodio -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB)
- #confirmation loop, if there are deletes user can review report before deleting
- $confirmation= Read-Host "Are you sure you want to delete all folders listed in red above? [y/n]"
- while ($confirmation -ne 'y') {
- if ($confirmation -eq 'n') {exit}
- $confirmation= Read-Host "Are you sure you want to delete all folders listed in red above? [y/n]"
- }
- #Deletion code, some checking if folder in fact deleted and warns if it has not been
- foreach ($delete in $deletes) {
- Get-ChildItem -Path $delete -Recurse | Remove-Item -force -recurse -ErrorAction SilentlyContinue
- Remove-Item $delete -Force
- [String]$exists=Test-Path $delete
- if ($exists -eq 'True') {write-host -ForegroundColor Red "Unable to delete folder, perhaps re-run script as administator or manually delete:" $delete}
- if ($exists -eq 'False') {write-host -ForegroundColor Green "Successfully deleted:" $delete}
- }
- #final modio size savings check and report
- $newsize=((Get-ChildItem $insmodio -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum)
- $newsizegb="{0:N2} GB" -f (($newsize) / 1GB)
- $removedspace="{0:N2} GB" -f (($ogsize - $newsize) / 1GB)
- write-host "********************************************"
- Write-Host "Modio folder Size before deletion" $ogsizegb
- Write-Host "Modio folder Size after deletion" $newsizegb
- Write-Host -ForegroundColor Green "Saved Space" $removedspace
- Read-Host -Prompt "Press enter to quit"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement