Montel IT Support Support when you need it, peace of mind when you don't.

The Safe Way to Name Files

Most of us save files, our data, onto computers we own, on systems in the cloud or both. Saving files is easy and most of the time it does not seem to cause problems.

Unfortunately, if you save files on one system and later on try to move, copy or send those files to a different system you can find yourself having all sorts of strange issues and failures. This is exactly what has happened to a friend of mine so I want to explain why it happens and give you some Golden Rules that will ensure you avoid these same errors.

All computers and other devices that can store data will use some sort of computerised filing system. This is usually called the File System (FS) and there are lots of them and they are all different. Microsoft have used ten different file systems, Apple have used six and there are at least 24 that have been used in different versions of Linux.

Some FS’s are used by many devices like the ISO 9660 standard commonly used for data written to CD’s. Others like NTFS are only used by Microsoft although some other computer systems are able to read and write to them with additional software. It is this wide range of different FS’s that is the root cause of the problems.

Each FS imposes its own set of rules on how a file can be stored. The trouble is that all the rules are different and that means that a file stored correctly on one FS may not compatible if moved to another type of FS.

Let me give you a very simple example of this.

Lets imagine I have a directory (folder) on my Linux computer that contains three files. You can think of a directory as a folder but in computing the correct term to use is directory. Feel free to use folder if you want to.

My Linux machines use a FS called ext4 and like all versions of the ext standard it is case sensitive. This means that the ext4 FS treats a capital letter differently to a lower case letter. As a result the ext4 FS can store the following three file names in the same directory (folder):

TERRY-TEST.doc
terry-test.doc
Terry-Test.doc

The ext4 File System treats each file as being different because it can see the differences in each of the file names. They can be stored and accessed without any problems on my Linux Mint system.

However, if I try to copy that directory over to a computer running Microsoft (MS) Windows I will get an error message. Windows will create the first file and then when it tries to copy the next file across it will complain that a file with the same name already exists. This is because the FS’s used by MS Windows are case insensitive. Any computer using MS Windows will treat a capital letter as being the same as a lower case letter.

On a computer running MS Windows my three files all appear to have exactly the same name and as that can never be allowed in any FS, not just those used by MS Windows, an error gets generated as soon as a new file tries to use the same name as one that already exists in the same directory. The only way I can get those three files to be saved correctly on a computer running MS Windows is to change two of the file names.

On a MS Windows machine I could call my three files:

terry-test.doc
terry-test1.doc
terry-test2.doc.

To be able to save the three files without errors I will need to rename them, or a copy of them, before I try to move them to any computer running MS Windows. The three files listed above could be copied to my Linux machine without any changes or errors because they are all unique.

Golden Rule Number One:

If you want to be 100% safe with file names ONLY use unique file names. Avoid using the characters case to differentiate file names, even on Linux or Unix systems. That way you will definitely avoid problems with the case sensitivity of different FS’s. One simple way to do this is to only ever use lower case for all your file names. It may not look pretty but it will never cause you any problems.

Illegal Characters.

Another problem that my friend has is caused by using illegal characters in file and directory names. Once again this is caused because the various FS’s have different rules on what characters are valid and what are illegal. To be honest it is pointless trying to list what characters are and are not valid on different FS’s as most of us will never know when we might be copying some files to a different FS.

The easiest way to avoid falling into this trap is to use a very limited range of characters in all your file and folder names. Never use the characters you find above the numbers on any keyboard. If you try to use things like * ? / \ | “ and others on a machine running MS Windows you will get errors trying to use the file even if it lets you save it first. Yes systems can really can be dumb enough to let you save the file with an illegal character but then give you errors when you try to use the file.

In my friends case some files have been saved with a ? at the end of the file name. Now I am unable to copy any of these files back to an external drive until I find all those files and get rid of the ? Character.

Golden Rule Number Two:

Only use A to Z, a to z and 0 to 9 plus – or underscore (_) for your file and directory names. On some FS’s even the underscore may cause problems and spaces can be another source of problems so try to avoid using them. Using any other characters is a guaranteed way to cause problems so just don’t do it.

Never ever use a period (.) or / or \ or | in any directory or file names as that really will break most FS’s and cause you some really baffling errors.

Never end a file or directory name with a space character either as this one is also the cause of some big problems and can be a real pig to sort out.

Look very carefully at any file name you get automatically when you download any files from the web or other cloud based services. They have a nasty habit of including illegal characters for the system you are using. Often you will be able to save the file but you may then find that you cannot open it or even find it. If you see anything that does not comply with our rule then edit the file name before you save it.

Path Lengths.

My friend has also fallen into another very common trap by using very long paths that are not compatible with all FS’s. The path is the full length name for every directory from the root level to and including the full file name.

As an example on a computer running MS Windows the path could be:

D:\Customer-Files\Laptop-specifications.odf

The path length has to include every character apart from the root drive letter. In my example we need to count all the characters after the D:\ so this example has a path length of 40 characters.

On the same drive I could also have the following path:

D:\Customer-Files\Hardware\Specifications\Apple\iMac\2013\21-Inch\Details.odf

The path length for this is 74 characters.

Once again different FS’s have different limits but to be safe the path length on any system should not exceed 255 characters. Ideally it will be less than 240 characters as that allows at least 15 characters for the file name. Keeping the path length short will always improve the compatibility of directories that you want to copy to different systems.

The longest path length I have found on my friends system is 284 characters.

Why Does This Happen?

In my experience many users think nothing of putting directories inside other directories, or folders inside other folders if you prefer. This may seem like a great way to tidy up all your files but it comes at a price. Every time you put one directory inside another one you are increasing the path length by the length of the directory names.

On modern graphical computers it is so easy to copy, or cut, and paste or just move files and more often folders with a few mouse clicks. You end up with what appears to be a well ordered and tidy system with folders inside folders inside folders inside folders...

But doing this can easily and quickly lead to excessive path lengths.

On my friends system over 18,000 files have a path length of at least 250 characters. No wonder I’m running into problems and errors when I try to copy the directories to another drive.

Golden Rule Number Three.

If you want to have a reliable FS and want to avoid running into problems when moving files and directories onto other systems keep the path length to an absolute maximum of 250 characters. Then your directory (folder) structure should still be compatible with all modern FS’s and you will avoid the sort of problems I’m currently dealing with.

Don’t drag one directory (folder) into another until you have checked its contents and are sure that doing so will not create any long paths. Otherwise you will simply be storing up trouble as well as making things harder to find in the future.

If you keep to my golden rules you should never have problems with files and directories when you want to copy them or move them to another system or bit of hardware. Time for me to get back to sorting out my friends system.

Your privacy really matters.
This website will NOT track you.

If you value your privacy I recommend that you use Firefox, Brave or Safari on an Apple device for your web browser. I also recommend using DuckDuckGo for your search engine.