Illegal File Names

“Illegal” in the rather peremptory manner of “computer-speak” that is..

Earlier this week, a client and I had problems transferring some data from an Apple Mac to a USB pen drive (or “memory stick”, if you insist on using that misnomer) prior to copying it onto a shiny new Windows 8 laptop.

Sopranos - Illegal Character?The copying process kept encountering forward slash and backslash characters contained within the names of files (eg a file’s name might have been “accounts at 31/12/2013”). Every time this happened the copying process just stopped dead with an error message. The problem arises because forward slash and backslash characters are permitted in the file system used by the Apple Mac operating system, but not in either of the two filing systems used by Windows (FAT and NTFS). The USB pen drive had been prepared (“formatted”) to use a Windows-friendly filing system and it just wasn’t going to accept files with “illegal characters”.

Question Mark
Another illegal character. It was very very hard finding images for this post!
What we did about it was to use the Mac’s spotlight (search) feature to list all of the files that included the offending characters and the client then manually changed all the filenames while I had more fun setting up the new laptop. There were a couple of hundred or so file names to change. Had there been thousands, I would have searched online for a utility (program) to automate the process.

How do you avoid such problems? In general, these things are only likely to crop up if you try to move something from a Mac system to a Windows system where there are characters that are illegal in Windows systems. If you think that there’s any chance that you might want to move or copy files in this way then don’t use the characters listed below in a Mac system, even though they are legal. You can’t fall foul of these rules while you stay within one operating system because that operating system won’t let you use a character that is illegal in that operating system’s filing system. The problem is only going to crop up if you transfer files between filing systems.

Mac Illegal Characters

  • :
  • Yep, that’s it. The only illegal character in OS9 and OSX is the colon. Further to that, though, you can’t use a full stop (aka a dot or a period) as the first character in a file name, as this would designate the file as hidden.
  • File and folder names can be up to 255 characters long in the current operating system (OSX), but only 31 characters in OS9.

Windows Illegal Characters

  • / ? < > \ : * | ”^
  • Actually, you can use the caret (“^”) in NTFS, but steer clear of it if you are likely to copy anything to a pen drive as it might be formatted as FAT.
  • I would also recommend steering clear of using a ~ (tilde) as Microsoft Office programs use this for a temporary version of the data file you have open (with a tilde as the first character). By the by, these temporary files are deleted automatically if you close the file correctly. If you find loads of Word documents or Excel spreadsheets on your hard drive whose names beging with a “~” then it’s a sign that you’ve not been closing your files and Office programs properly. As long as the programs are not currently running, it’s safe to delete such files.
  • File and folder names can be up to 255 characters long in FAT and 256 in NTFS.
  • Also, there are some “reserved names” in Windows that have been used to designate specific things (serial and parallel ports, if you must know). So, you can’t use the following as file or folder names – com1, com2, com3, com4, com5, com6, com7, com8, com9, lpt1, lpt2, lpt3, lpt4, lpt5, lpt6, lpt7, lpt8, lpt9, con, nul, and prn.

We’ve only been looking at file names here. Just because a file can be transferred between a Mac and a PC (in either direction) without falling foul of these naming rules doesn’t mean that the receiving system will be able to deal properly with the file. Whether you can actually open and read a file created on another system is dependent on having a program capable of understanding the contents of the file. You can rely on common types of files (such as pdf files and image files) being happy on any system, but proprietory files (eg those produced by accounts systems) may need some “conversion” or “importing” process. Such processes – if they exist – would be found within the program that is going to use the file.