Created
February 26, 2016 05:00
-
-
Save lamchau/fedd26a438cd7b2a124b to your computer and use it in GitHub Desktop.
multithreaded large folder delete on windows
This file contains hidden or 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
# for deleting large directories (e.g. node_modules) | |
function purge($target_dir) { | |
if (Test-Path -Path $target_dir) { | |
$uuid = [guid]::NewGuid().toString() | |
$empty_dir = "$env:temp$uuid.tmp" | |
New-Item -ItemType directory -Path $empty_dir | Out-Null | |
# delete using robocopy /NFL ... (options to suppress stdout) | |
robocopy $empty_dir $target_dir /MIR /MT | Out-Null | |
Remove-Item $empty_dir | Out-Null | |
$target_dir = (Resolve-Path $target_dir).Path | |
Remove-Item -Recurse -Force $target_dir | Out-Null | |
Write-Output "Deleted: $target_dir" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment