How to delete a file in Windows with a too long filename?

I came across a situation where I had to remove all files at this location C:\Users\{username}\AppData\Local\Temp.  I was able to delete most of the files however I came across a Windows error stating that one or more files had a file name too long to be removed.  I tried a number of approaches (not to be stated here) however the resolution was to use RoboCopy.

I created a local directory c:\temp\empty_dir with nothing in it.

I then used the following RoboCopy command to mirror that empty directory with the problematic directory.

robocopy c:\temp\empty_dir C:\Users\{username}\AppData\Local\Temp /s /mir

This works because robocopy internally uses the Unicode-aware versions of Win32 functions, with the \\?\ prefix for file paths; those functions have a limit of 2¹⁶-1 (32,767) characters instead of 259




comments powered by Disqus


Recent Tweets

Retweeted by @dyardy Hey C# peeps, we’re trying C# in browser with reference content. Try it here:… reply with feedback /cc @LadyNaggaga
23 Amazing Vintage Photographs Taken Inside WWII Tank Factories ~ vintage everyday…
When is AI NOT Search? Artificiality intelligence==Search Engine (there cases when this is not true)
@projectedxyz Large data vs big data? Industry has so misused buzz words to sell products, and so you end up nothi……