How to Delete an Excessively Long Directory on NTFS

The current version of Windows has some throwbacks to the days of the DOS operating system. Back in the day, DOS had a limit on filenames that they could not be more than 260 or so characters long (there was a little fudging between the limit on directories and filenames, but let's just call it 260).

The current NTFS file system doesn't have that 260 character limit. However, many of the tools that talk to NTFS, like the Windows Explorer and the command line still do have the limit. So if you have a tool that doesn't have the limit, it can create a directory that you cannot delete from the Windows Explorer or the command line. Arg!

The solution is to make the entire directory path shorter than 260 characters, then you can delete the directory. Go to Windows explorer, and drill down into your excessively long directory path until you cannot go any deeper. Then drag that deepest directory you can reach and move it to be a subdirectory of the root (or somewhere much further up the directory tree if the name conflicts). Delete the directory path that you dragged from, which should now be short enough to delete. Then drill down in your new path from the root...you should be able to reach further down than you could before because the limit only applies from the root. Repeat again and again until you can get to the bottom of the tree.

As an additional note: The most common reason for the long directory name problem is that Windows has a bug where it creates a recursive reparsepoint for a directory called "Application Data". This puts the directory as a subdirectory of itself. This means that you can into this subdirectory forever. So if you use a tool like robocopy to copy the directory tree, it will drill down until it hits the NTFS limit on the directory name (much longer than 260) and keep copying the directory. Then you can't delete the directory it copied. To remove a reparsepoint, you can do the following commands from a command prompt:

cd "\users\myacct\appdata\local\application data"
fsutil reparsepoint delete "application data"

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.