diff --git a/scripts/cd-scripts.ps1 b/scripts/cd-scripts.ps1 index 6e52fa74..4daf9457 100755 --- a/scripts/cd-scripts.ps1 +++ b/scripts/cd-scripts.ps1 @@ -5,7 +5,7 @@ This PowerShell script changes the working directory to the PowerShell scripts folder. .EXAMPLE PS> ./cd-scripts.ps1 - 📂C:\Repos\PowerShell\scripts + 📂C:\Repos\PowerShell\scripts entered (has 644 scripts). .LINK https://github.com/fleschutz/PowerShell .NOTES diff --git a/scripts/remove-old-dirs.ps1 b/scripts/remove-old-dirs.ps1 index 502429c3..fd111814 100755 --- a/scripts/remove-old-dirs.ps1 +++ b/scripts/remove-old-dirs.ps1 @@ -9,7 +9,9 @@ Specifies the number of days (1000 by default) .EXAMPLE PS> ./remove-old-dirs.ps1 C:\Temp 365 - ✅ Removed 0 subfolders in 1s (67 skipped). + ⏳ Scanning C:\Temp for subfolders older than 365 days... + ⏳ Removing old 'TestFolder'... + ✅ Removed 1 of 49 subfolders in 1s. .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -24,21 +26,19 @@ try { if (!(Test-Path -Path "$path" -PathType container)) { throw "Given path doesn't exist - enter a valid path, please" } Write-Host "⏳ Searching in '$path' for subfolders older than $numDays days..." - $numRemoved = $numSkipped = 0 + $numRemoved = 0 $folders = Get-ChildItem -path "$path" -directory foreach ($folder in $folders) { [datetime]$folderDate = ($folder | Get-ItemProperty -Name LastWriteTime).LastWriteTime if ($folderDate -lt (Get-Date).AddDays(-$numDays)) { - Write-Host "Removing old '$folder'..." + Write-Host "⏳ Removing old '$folder'..." $fullPath = $folder | Select-Object -ExpandProperty FullName Remove-Item -path "$fullPath" -force -recurse $numRemoved++ - } else { - $numSkipped++ } } [int]$elapsed = $stopWatch.Elapsed.TotalSeconds - "✅ Removed $numRemoved subfolders in $($elapsed)s ($numSkipped skipped)." + "✅ Removed $numRemoved of $($folders.Count) subfolders in $($elapsed)s." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"