Long Filenames – How Long is Too Long

A quick plug to help pay the bills. To see how FileBoss can help you find long path names on your system and what to do with them see Finding Long Filenames and Paths.


m-find-long-filenamesThere is a lot of confusion and much speculation on the Internet as to what constitutes a filename or path that is too long for Microsoft Windows. 256? 260? 259? 32,000+? 180? 247? 248? The confusion is understandable since all those – and more – are correct and they are wrong and they are sometimes correct and wrong at the same time.

More about the confusion later I’ll start with just a little overview and then get to the good stuff.

What is a filename

When it comes to names and paths, folders (directories) and filenames are exactly the same: all rules that apply to filenames also apply to folder names. There is a common misconception that folders don’t have extensions (the name after the dot). But that is just a convention that developed from the way Microsoft first named most of Windows’ system folders many years ago. Any folder can have an extension just as any filename can exist without one. So when I mention filename in the rest of this post I’m also referring to folder names unless explicitly stated otherwise.

There are three parts to a full pathname.

  • the drive or volume (for example as C:\ and \\Server\)
  • the path to the file (for example backup\accounts\2012-08-30\)
  • the actual filename and optional extension (for example checklog.db)

Combining all three parts results in a fully-qualified filename (fully-qualified meaning that it is uniquely identified by having all three parts) would be something like C:\backup\accounts\2012-08-30\ checklog.db. Just to have a little pity on my fingers and keyboard I’ll refer to a fully-qualified filename as a pathname.

The quick and the simple rule of filename lengths

If you want to skip the following explanations of the (semi-)exact maximum lengths. Just remember that you really shouldn’t create any file with a total pathname length (drive, path, and filename and extension) greater than around 230 characters (and even then much shorter would be better. And perhaps even more important don’t create really long filenames for as they are copied around the will easily be copied to folders that already are long making them exceed the limits that can be handled by one program or another.

For example if you create a filename that 240 characters long, say something like:

Annual report on the average gestation period of North American pelicans by professor emeritus…..issued on July thirteenth in the year two thousand and thirteen…and originally present to the symposium on….well received.docx

All may go well until the file gets copied to: \\AcmeCorpnet\backup\boring-papers which will create a pathname in excess of any reasonable limit and will create problems someone in the future.

The gory details on maximum filename lengths

Here is where the numbers come from in the traditional, as in original, Windows file system:

260 – Because there was only space to store 260 characters for each pathname. However, this is really only of significance to systems programmers and numerologists.

259 – Because one of those bytes had to be a null or 0 at the end of the string. You can’t see this last byte it is just there so that Windows and Windows programs would know where the end of the filename was. So that left only 259 possible characters in the visible, fully-qualified filename.

256 – Because some young, smart-aleck (who is by now an old, potbellied head of some insignificant section of a small computer department somewhere) said, “Well the drive isn’t part of the path name and that is three characters long (a letter, a colon, and a backslash e.g., C:\) so really the maximum length is 256 characters”. Why anyone listened to that smart-aleck I don’t know but people did and 256 became the number that people who knew little would utter with a condescending nod of the head indicating they knew a lot.

248 – I’ll explain this and the next one but you might just as well forget them immediately unless you can use them to impress your boss, your friend or your significant other. 248 equals 260 minus 12. Brilliant! why minus 12? Because that was the maximum length of a filename – 8 characters plus a dot plus a three character extension. And since a path always had to have space for a filename to be added to it, it couldn’t be longer than 248 characters. Of course this is the maximum length of a path without a filename, which really can’t exist by itself.

247 – Same as above except that the 12 characters for the name is subtracted from 259 instead of 260 as these people didn’t see and thus didn’t know about the trailing 0 (remember those people?).

180 – The approximate maximum length allowed by some file systems used when writing to CDs and other round, thin, removable media. The important thing to note here is that 180 is an approximate number that may vary a bit from CD to CD for various technical reasons only understood by those who decided to set the maximum filename for these devices to 180, approximately.

32,000+ – Available on some modern versions of Windows and modern file systems. Don’t count on this unless you really know what you are doing and are not adverse to experiencing true disaster down the road.

But wait – it gets worse

The usable maximum pathname length depends not only on the storage media and version of Windows but also the programs that will be working with the file as some programs have smaller limits on file length and while these are becoming less and less common they still exist. But was is even worse is that some Windows functions can’t handle as long pathnames as other parts of Windows so you may be able to copy a file but not delete it.

We will discuss how to find files with pathnames long enough to create problems and how to handle them in a post later this week.

 

Tagged with: , , , , , , ,
Posted in Filenames, Long Filenames, Renaming
Archives
List posts by category
Other pages