I’m fastidious when it comes to keeping things like my hard drive and emails in order. I hate clutter, both in the real and virtual world.
So imagine my disbelief when I was tidying up some old files on my hard drive recently, only to find that I couldn’t delete them because the file names were too long. At first, I couldn’t work out how to delete these files with a long file name. However, I soon worked it out.
Why is there a limit?
Good question, I’m glad you asked. Here is a quote from MSDN:
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is “D:some 256-character path string” where “” represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
So the full file name contains a lot more than just the name of the file itself. It’s actually made up of
[drive][:][path][null], or 1+2+256+1 (260).
This explains how the limitation works, but it doesn’t explain why. I can only assume that there is a 256 character path string limit because 640k of RAM is enough. 😉
You’re boring, how do I delete the files?
Ok, ok. Enough messing around. Let’s look at how you can actually delete these annoying files with long file names. There’s loads of guides online that say you should use the
[filename] /x command to show the short filename, then delete the file using that.
For me, that didn’t work. My way is actually much more simple than that. Using command line, use the cd command to browse to the path that contains the long filename e.g. –
C:> cd c:pathtolongfile.
Then, use the del command to delete the file and combine it with the /f flag to force the removal of the file e.g. –
C:\<pathtolongfile> del /f reallylongfilename.docx.
Using these really simple commands should force the file to be removed from your Windows system. Well, it did for me at least. How easy was that?!