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

@jeffrey_doucet @Brian_Bancroft Canadians, self define themselves as NOT American, rather than being Proud Canadians
Retweeted by @dyardy Why do so many Canadians obsess over American policy that won’t impact us while being fairly ambivalent to day-to-d……
@melrobbins I was looking for 50$ earlier today, and still can't find it...ideas :)
Trump Watches Up To 8 Hours Of TV Per Day | HuffPost #SmartNews ===that explains everything…
Retweeted by @dyardy Boston