Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryanwischkaemper/ef80233b2eea0eb4d939 to your computer and use it in GitHub Desktop.
Save ryanwischkaemper/ef80233b2eea0eb4d939 to your computer and use it in GitHub Desktop.
Remove directories on Windows that have really long file paths in them
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