Windows hates long filenames

.. which is kind of a bummer, since the Node package manager really loves them. I thought Windows was kidding me, but apparently you can manage to paint yourself into a corner where you have a perfectly valid, browse-able directory structure – except you can never delete it.

I try to rename the offending folder and I get this:

Every possible offending application has of course been closed. If I didn’t have such a massive love for life, I’d be stabbing myself in the face by now.

After running CHKDSK.EXE, Windows gives me this:

Windows hates long filenames

This is where I decide that a reboot is the way to go. If I said I was surprised when I saw this, I’d be lying. It’s just that kind of day:

One reboot later, nothing has changed. My directory structure looks like this:

Now, coming from a Linux/Max/Unix world, this would be no problem at all, which is probably why I’m shocked that Windows thinks so. After a lot of trial and error, it looks like I’ve found the horrible bastard of a solution: start from the leaf directories and traverse the tree upwards towards the root, renaming each directory to a one character name in the process. At one point the directory structure becomes “unlocked” again, and you can delete it. Sort-of-deleting-them-and-instead-moving-them-to-the-recycle-bin will probably yield this result:

Which is pretty weird, since Windows is now asking me to ask myself for permissions. Hitting shift+delete instead of just delete seems to solve that.

I’ll update this post if I ever find less bizarre way of solving this issue.

UPDATE: So, Windows has a hard limit of 260 characters in the total length of the path, including separators and a terminating null. Microsoft claims thie is a feature, not a bug, and will not fix it. And here is where it gets weird, because they sort of have already. There are two APIs for accessing the file system – one with a 260 character limit, and one that offers unicode and a 32K character limit. Node seems to use the newer API, and as a result does not have any trouble creating deep directory structures. Something inside the belly of the Windows beast itself still uses the old API, which is why it breaks when you try to remove a structure created by something like Node. This takes stupid to a whole new level.

“Do you have a cleaner way to fix this” you ask. Yes. If Node and possibly Gulp is why you got into this mess in the first place, you should install a plugin like gulp-clean and use that to remove folders like node_modules and bower_components. I suggest a task name like dist-clean. Linus would love that.

Posted Monday, June 23rd, 2014 under Uncategorized.

Leave a Reply

You must be logged in to post a comment.