Created
February 13, 2016 04:50
-
-
Save ryanwischkaemper/ef80233b2eea0eb4d939 to your computer and use it in GitHub Desktop.
Remove directories on Windows that have really long file paths in them
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
function Remove-DirectoryWithPathTooLongFileNames(){ | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true, Position=1)] | |
[ValidateScript({ Test-Path $_ })] | |
[String]$folderPath | |
) | |
$dirInfo = New-Object -TypeName System.IO.DirectoryInfo -ArgumentList $folderPath | |
$parentFolder = ([System.IO.Directory]::GetParent($dirInfo.FullName)).FullName | |
$tempFolder = Join-Path $parentFolder 'temppurger' | |
if(!(Test-Path $tempFolder)){ New-Item -Path $tempFolder -ItemType Directory > $null } | |
robocopy.exe $tempFolder $folderPath /purge > $null | |
Remove-Item $tempFolder | |
Remove-Item $folderPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment