Created
July 4, 2014 05:58
-
-
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.
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
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