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

Maybe resolved itself, after resetting emulator and couple restarts - will let you know
@MillerMark A few weeks ago you tweeted that something huge/incredible was coming....what is/was it? (I am hoping s……
Oddly, it won't hit breakpoints in XF .net standard 2 project now either
@JamesMontemagno Updated to 15.7 preview 2 Visual Studio - now having lots of odd thread issues when starting debug……