mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-23 10:28:23 +02:00
Updated remove-old-dirs.ps1
This commit is contained in:
parent
ba6f1594c8
commit
a3331f5172
@ -8,7 +8,8 @@
|
|||||||
.PARAMETER numDays
|
.PARAMETER numDays
|
||||||
Specifies the number of days (1000 by default)
|
Specifies the number of days (1000 by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./remove-old-dirs.ps1 C:\Temp 90
|
PS> ./remove-old-dirs.ps1 C:\Temp 365
|
||||||
|
✅ Removed 0 subfolders in 1s (67 skipped).
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -22,7 +23,7 @@ try {
|
|||||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
if (!(Test-Path -Path "$path" -PathType container)) { throw "Given path doesn't exist - enter a valid path, please" }
|
if (!(Test-Path -Path "$path" -PathType container)) { throw "Given path doesn't exist - enter a valid path, please" }
|
||||||
|
|
||||||
Write-Host "⏳ Searching for subfolders at '$path' older than $numDays days..."
|
Write-Host "⏳ Searching in '$path' for subfolders older than $numDays days..."
|
||||||
$numRemoved = $numSkipped = 0
|
$numRemoved = $numSkipped = 0
|
||||||
$folders = Get-ChildItem -path "$path" -directory
|
$folders = Get-ChildItem -path "$path" -directory
|
||||||
foreach ($folder in $folders) {
|
foreach ($folder in $folders) {
|
||||||
@ -37,7 +38,7 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"✅ Removed $numRemoved subfolders older than $numDays days in $($elapsed)s ($numSkipped skipped)."
|
"✅ Removed $numRemoved subfolders in $($elapsed)s ($numSkipped skipped)."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user