Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created July 4, 2014 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/8e4d827d6c116ceeaf12 to your computer and use it in GitHub Desktop.
Save bill-long/8e4d827d6c116ceeaf12 to your computer and use it in GitHub Desktop.
This script uses Microsoft.Experimental.IO.dll (see http://bcl.codeplex.com/wikipage?title=Long%20Path) to delete folders which contain files where the path exceeds 260 characters. This script recursively deletes all files and folders in the specified folder.
param($folder)
$ExperimentalIOBinary = 'C:\Users\administrator\Desktop\Microsoft.Experimental.IO.dll'
[System.Reflection.Assembly]::LoadFile($ExperimentalIOBinary)
function DeleteAllFilesRecursive($path)
{
"Getting folders in folder: " + $path
$subfolders = [Microsoft.Experimental.IO.LongPathDirectory]::EnumerateDirectories($path)
foreach ($subfolder in $subfolders)
{
"Recursing folder: " + $subfolder
DeleteAllFilesRecursive($subfolder)
"Deleting folder: " + $subfolder
[Microsoft.Experimental.IO.LongPathDirectory]::Delete($subfolder)
}
$files = [Microsoft.Experimental.IO.LongPathDirectory]::EnumerateFiles($path)
foreach ($file in $files)
{
"Deleting file: " + $file
[Microsoft.Experimental.IO.LongPathFile]::Delete($file)
}
}
DeleteAllFilesRecursive $folder
"Deleting folder: " + $folder
[Microsoft.Experimental.IO.LongPathDirectory]::Delete($folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment