Created
June 25, 2012 23:53
-
-
Save evenkiel/2992175 to your computer and use it in GitHub Desktop.
Powershell function to recursively delete a folder and all of its child folders and files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Given a root directory, perform a depth first recursive delete of all subdirectories and files. | |
# Necessary b/c for some reason powershell won't always succeed in a recursive delete of folders which contain | |
# subfolders | |
# | |
function RecursiveDelete($theroot) { | |
$children = Get-ChildItem -Path $theroot | where-object { $_.Attributes -eq "Directory"} |% {$_.FullName} | |
foreach($achild in $children) { | |
if ($achild -ne $null) { | |
RecursiveDelete $achild | |
} | |
} | |
Remove-Item $theroot -recurse -force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this gist!