Deleting files with “too long filenames” in Windows

If you’re using Microsoft Windows and happen to have a file that has a very long filename, more than 260 characters to be percise, you’re living in a hell… Nothing can be done with it! Unless you use a great little tool of course, Robocopy!robocopy

Robocopy is an old product that comes with Windows since Vista (i think?) an can be accessed via Powershell. The thing with Robocopy is that it’s main purpuse is to copy files in one way or another. It has a feature for Mirroring one folder to another. With that said, what happens when you mirror an empty folder with a folder containing files with names too long? You get two empty folders! :) Life’s good!

The basic command for doing this is:
robocopy.exe c:\My\Empty\Folder c:\Folder\With\Long\Names /MIR

What I used this for was cleaning up the INetCache folder that had gone wild and crazy and gave the users alot of problem.
The script I used to clean this folder was:
Get-ChildItem X:\Profilefolder | foreach {robocopy X:\Empty (“X:\Profilefolder\” + “$_” + “\AppData\Local\Microsoft\Windows\INetCache”) /MIR}

This just lists all entries in X:\Profilefolder and handles each entry with a robocopy command that is mirroring the empty folder with the INetCache folder.

Reference:
http://technet.microsoft.com/en-us/library/cc733145.aspx

Posted in Microsoft, Misc.