mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-12 22:17:17 +02:00
Updated remove-dir-tree.ps1
This commit is contained in:
@ -7,6 +7,7 @@
|
|||||||
Specifies the file path to the directory tree
|
Specifies the file path to the directory tree
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./remove-dir-tree.ps1 C:\Temp
|
PS> ./remove-dir-tree.ps1 C:\Temp
|
||||||
|
✅ Removed directory 'C:\Temp\ in 9s.
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -17,9 +18,13 @@ param([string]$pathToDirTree = "")
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if ($pathToDirTree -eq "" ) { $pathToDirTree = Read-Host "Enter the path to the directory tree" }
|
if ($pathToDirTree -eq "" ) { $pathToDirTree = Read-Host "Enter the path to the directory tree" }
|
||||||
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
Remove-Item -Force -Recurse -Confirm:$false $pathToDirTree
|
Remove-Item -Force -Recurse -Confirm:$false $pathToDirTree
|
||||||
|
if ($lastExitCode -ne 0) { throw "'Remove-Item' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
|
"✅ Removed directory '$pathToDirTree' in $($elapsed)s."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Reference in New Issue
Block a user