Renaming long file names in Windows

So, I noticed that dirvish was blowing up on a Windows Server 2003 backup. Looking at the logs, I noticed it was in reference to a file that was named with a large file name. I have no idea how Windows allows this, yet complains about it.

Hopping on to that box, I was having trouble immediately with this file. Could not move it, rename it, delete it, etc. I even tried to delete the folder it was in, etc. Tried all the various renames with * and quotes, etc. No dice. I finally found out it was an issue relating to file name length AND directory path. Okay, now we're getting somewhere.

I opened a command prompt and navigated to that directory. From there, I created a temporary mapped drive:

subst T: .

Then I went there:


After I'm in the mapped drive, I tried the rename:

rename "my long lame file name.png" tmp.png

When I was done, I moved myself out and removed the mapped drive

subst T: /d

Very slick!