What’s In a (File) Name ?

We don’t often think about filenames now – the length of the name, or the characters that make up the name – but this wasn’t always the case. But lately, recent advances can mean that just a little more thought might be required when choosing a name for your files.

If you haven’t got time to read this entire article the main point is that it may be prudent to keep your filenames (and the names of folders in which they are stored) shorter, more succinct, and avoid using certain characters (spaces being one of them)  if you wish to avoid problems.

A Little History of Filenames

Back in the mists of time when the “MS-DOS command line” was king and a mouse was something undesirable that lurked behind the refrigerator, filenames were a simple affair. You were allowed up to 8 characters in the filename (letters and numbers only) followed by a period (full stop) followed by a 3 character filename extension that was used to identify the type of file you were saving. This was called the 8.3 filename system.

A typical DOS screen image showing 8.3 filename styles

Filename extensions were always visible and took the form of “TXT” for a text file, or “DOC” for a Microsoft Word document, of “XLS” for an Excel spreadsheet, and so on. These extensions were created automatically and appended to the filename by the software that saved the file.

The filename itself was limited to 8 alphanumeric characters. You could type in upper and lowercase but the filename itself was always stored in uppercase. You could NOT use a space within the 8 characters, as the space would be interpreted as the end of the filename so that a filename of “MY FILE” would be interpreted as, simply “MY”.

Folders were allowed and folder names followed the same rules – 8 characters only, without the extension.

The full location of a file (i.e. the “path” to that file) was known as the pathname. This consisted of the drive letter (including a colon : to indicate a drive) on which the file was stored, followed by the name of each folder in which the file was stored, followed by the filename itself, with each part separated by the backslash \ character. Thus a typical pathname might appear as follows –

C:\WORDDOCS\MYDOC1.DOC

This example describes a Word Document (DOC) file called “MYDOC1” which is stored in the folder “WORDDOCS” on the C-Drive of the computer.

If there was a sub-folder called LETTERS within WORDDOCS in which the document was stored then this would appear as –

C:\WORDDOCS\LETTERS\MYDOC1.DOC

Long Filenames

As computers became more powerful and storage space became larger and cheaper there was a need for longer filenames and pathnames. Pathname length was increased up to 256 characters in total, upper and lowercase characters were allowed, and spaces were permitted in the names to improve legibility.

At some point too, the option to hide filename extensions was offered, so that you no longer saw the “.DOC” part at the end of the filename. The limit of the filename extension size was also removed, although most extensions today remain within 3 to 4 characters in length.

With the advent of Windows 10, the theoretical pathname length was increased again – up to 32,767 characters ! So Windows itself can handle massive pathname lengths but most software and apps do not. The practical limit for pathnames therefore remains around 256-260 characters.

The point is, however, that it seemed we no longer had to worry about filename lengths, or what we chose to call files – we could simply make the filename a description of the file contents which would easily fit with 256 characters. For example –

C:\Users\User\Documents\Letters Home\Please send me more money again.doc

And Then Came the Web

Everything was sort of working ok for filenames for a while but then an important change came along – the internet. HTML, the language that controls the internet, does not like spaces in filenames. To get around this problem spaces are automatically replaced by a string of 3-characters %20 when the filename is processed. This changes a filename as follows –

Please send me more money again.doc    would now become

Please%20send%20me%20more%20money%20again.doc

Importantly this increases the filename length, since every single space in the name is replaced with three characters. In this example the 5 space characters become 15 characters, so the 35 character original name becomes 45 characters in length. In a long pathname, with lots of spaces, this can lead to a significant increase in path length when passed through HTML and the internet.

But why do internet filename limitations matter when you are creating pathnames for your own computer, not the internet ? Because of what happened next.

Along Came Cloud Storage

A big advance in file storage came about with the drop in cost for online, “cloud” storage. Systems like DropBox, GoogleDrive, and OneDrive all store your files, with your pathnames, via the internet, to remote storage devices. These systems use the HTML internet language, therefore spaces in pathnames are substituted with the %20 characters at some point in the process. You may never see those %20 characters but they are used within apps.

Other pathname changes may also come about as hidden “server names” or “user identifier codes” are added to the front of your chosen pathname in order to locate a file correctly over the internet. These name changes are often hidden from view, so as not to confuse the user. But they are present, and can cause issues when they increase the pathname length.

So What Exactly Is the Problem ?

Let’s suppose you are setting up a cloud-based storage system on your computer – e.g. OneDrive. You open the OneDrive folder and start to create a system of folders and sub-folders, each with clear, meaningful (occasionally long) filenames. Some of those filenames have spaces in them to make them easier to read.

Next you move files to the OneDrive folder and sub-folders and, again, some of these files have long filenames with spaces.

Windows has no real pathname limit and OneDrive has a published limit of 400 characters so no pathname you create is anywhere near that sort of length.

Then you open a document in Word, edit it, and use File – Save As to save the document with a slightly different filename and receive the following error –

Error in Microsoft Word

But the filename is valid ! It contains no bad characters and Word allowed you to open the original in the first place. You didn’t “incorrectly type” the path – you are simply using the path of the original document, which Word allowed you to use when the original was opened.

So you might change the last part of the filename, maybe reduce it in size a little, but still you get the same error message and you are unable to save the file.

The problem is that the full pathname, including all the %20 strings that have been used to replace spaces in the name, exceeds the 259 character limit allowed by Microsoft Word when creating a new file. Due to the way spaces are handled, the pathname could exceed this limit by a significant number of characters, so reducing the last part of the name by a few characters may not make any difference.

This is a limitation imposed by the software app you are using – in this case Microsoft Word – and not by Windows or OneDrive. And importantly, this limit is imposed when creating (i.e. Saving) the document, not when opening it. Interestingly enough, the File – Save option may still work, since that simply updates the existing file rather than creating a new file, but File – Save As will not work.

How to Fix The Problem

First you need to save the document, so as not to lose any data. You can save it to the “Documents” folder on your computer (which will have a much shorter path) rather than the original OneDrive path, then move the file later.

Select  File  then Save As  then look for the “Other locations” area and select “This PC”

Select “This PC” to save to the Documents folder rather than OneDrive

This will set the current storage location to the “Documents” folder on your computer. This clears the original, long, OneDrive pathname and will allow you to save the file.

Once saved, you can close Word the use File Explorer to move the file from your Documents folder to the appropriate location on OneDrive. This solves the immediate issue of saving the new file.

Next you must investigate the cause of the issue, by checking the pathname lengths in OneDrive, and then resolve the issue for the future.

File and Folder Name Guidelines

To avoid problems in the future there are a few guidelines for file and folder names you can follow.

Firstly, be aware of creating long names. The name doesn’t have to read perfectly so can you shorten the name but retain it’s meaning ?

  • Instead of        ….\Folder for storing accounts for the year 2018 to 2019
  • Use                     .…\Accounts2018-19

Use Uppercase letters to separate words instead of using spaces or, if you must have some white space between characters then, use either an underscore or a dash instead of a space character –

  • Instead of            Best filing practices to avoid filename length issues.doc
  • Use                        BestFilingPracticesToAvoidFilenameLengthIssues.doc
  • Or                           Best_filing_practices_to_avoid_filename_length_issues.doc
  • Or                           Best-filing-practices-to-avoid-filename-length-issues.doc

The original filename above is 57 characters in length and contains 7 spaces. This would become 71 characters in length when the spaces are replaced with %20 strings for HTML use. The first “best practice” example reduces this to 50 characters which saves 21 characters compared with the original HTML filename.

There are also some particular non-alphanumeric characters that should be avoided in filenames. These are as follows –

~   ”  #  %  &  *  :   <  >  ?  /  \  {  |  } 

For more information see the Microsoft documents linked to below –

Microsoft Bad Pathnames

Microsoft Office Apps Pathname Limits

You do not have to rename every folder in the path. Concentrate on those folders with the longest names and reduce the length of those first.