Thursday, May 10, 2012

Deleting very long file paths on NTFS volumes

It's the end of the Spring semester here, and that means that it's time to clean up the year's mess. Typically, this means disabling AD accounts for graduates, removing their network shares, etc. We have a monolithic home-grown VB program for this (gross, I know), but occasionally some oddities slip though the cracks.

One such oddity was the network folder of one of the computer science students. The path on the server looked like this:

E:\users\u\username\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\csc290\assignment8\

except that it went on FOREVER. There we no files in place, there were no hard links or junctions in play. There were just a ton of folders of the same name nested inside of each other. I, literally, have no idea how the student was able to do this, but it happened.

I tried navigating deep using \\?\E:\users\u\username\ blah blah blah, but even using that syntax, I couldn't delete it. After about an hour of trying to use subst (over and over), to shorten the path and trying to find a command-line delete tool that works with long file paths, I finally decided to give robocopy a try.

I ended up using the /mir switch to mirror an empty folder into the screwed up one. The command looked like this:

robocopy c:\empty e:\users\u\username\csc290 /mir

This took a little while to run, but eventually the top csc290 directory was emptied and I was able to delete the user's folder without a problem.

3 comments:

  1. Well. Long path tool can be helpful on this situation. Thanks

    ReplyDelete
  2. Had this issue in the past (in fact caused by using robocopy without the /XJ switch) wound up rebuilding the system. Thanks for the tip, i'll try this next time I come across it. :)

    ReplyDelete
  3. Try using Long Path Tool. It works nicely.

    ReplyDelete