You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Slashes in file names

Ever since OSX came along the great and the good have told us:
"Don't use slashes in your file names. The system reserves them for its own Special Purposes and you might run into problems if you include a slash (or a colon) in the file name. Just don't do it. Okay?"

So, I was making a backup of my Apple Address Book data file and what default name did the application give to the backup file?

Address Book - 25/02/2006

So why does one of Apple's own applications automatically create file using a supposedly illegal character? Does it mean that I can use slashes in my file names again?

Do as I say, not as I do, huh, Apple?

G5/2GHz x2, Mac OS X (10.4.7)

Posted on Oct 5, 2006 6:33 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 5, 2006 7:05 AM

A lot of the code in OSX is from Unix. Unix does not allow the slash "/" in filenames because it is used to separate folders in a path name. i.e. /Users/Fred/Library/Preferences...
Machintosh software used colon ":" for that purpose.

When dealing with Mac software, (e.g. Finder, HFS+ disk file system) you can use the slash, but not the colon.
When dealing with Unix software (e.g. Terminal, UFS) you can use the colon, but not the slash.

As a file name is passed though various layers of software, colons and slashes swapped, as needed, to keep the file name valid for the type of software that is using it.
If you create a filename containing a slash with Mac software, then look at it with terminal, you will see the filename with a colon.

Normally everything takes care of itself, but if you burn a disk and use it on a different operating system, interesting things may happen if filenames contain a slash. For example somebody was burning a CD with files named:
F/ABC.DEF
Windows XP read it as:
F:ABC.DEF
and had trouble finding the drive "F"
10 replies
Question marked as Top-ranking reply

Oct 5, 2006 7:05 AM in response to Rick Lecoat

A lot of the code in OSX is from Unix. Unix does not allow the slash "/" in filenames because it is used to separate folders in a path name. i.e. /Users/Fred/Library/Preferences...
Machintosh software used colon ":" for that purpose.

When dealing with Mac software, (e.g. Finder, HFS+ disk file system) you can use the slash, but not the colon.
When dealing with Unix software (e.g. Terminal, UFS) you can use the colon, but not the slash.

As a file name is passed though various layers of software, colons and slashes swapped, as needed, to keep the file name valid for the type of software that is using it.
If you create a filename containing a slash with Mac software, then look at it with terminal, you will see the filename with a colon.

Normally everything takes care of itself, but if you burn a disk and use it on a different operating system, interesting things may happen if filenames contain a slash. For example somebody was burning a CD with files named:
F/ABC.DEF
Windows XP read it as:
F:ABC.DEF
and had trouble finding the drive "F"

Oct 5, 2006 7:32 AM in response to Rick Lecoat

Malcom's information is right on target. The only omission is that you can create such filenames using Unix's special escape character, the backslash, or by enclosing the filename in quotes. For example, 25\/02\/2006 will treat the forward slash as a character in the filename rather than the standard Unix path separator. Alternatively, '25/02/2006' or "25/02/2006" will accomplish the same result. In fact you need to enclose filenames with special characters and spaces in quotes or use the backslash before each character in order for Unix to treat the filename correctly.

In general, however, it's best to avoid confusion by simply not using any of Unix's special characters in filenames.

Oct 5, 2006 7:59 AM in response to Kappy

Malcolm: yes, that's what I understood (in a much less technical way though, so thanks for filling in the gaps there). I hadn't realised that software would swap characters around on my behalf, however.

Kappy: I agree entirely that it is best to avoid 'special' characters in file names, and I have always endeavoured to do so. The query behind this thread, I guess, was why Apple themselves do not see fit to follow this advice and allow the default file name provided by certain applications (in this case Address Book) to include characters that might cause problems. They have clearly stated that these characters can be problematic and should be avoided. So I wonder why they use them themselves?

Thanks to both of you, in any case.

Oct 5, 2006 8:06 AM in response to AJ

AJ:

yes, I always restrict my file names to a-z, A-Z, 0-9, _ (underscore) and - (dash). That way I never have any problems, although I wish that OSX would treat underscore as a word divider. Currently, double clicking the last part of the filename document_001 selects the whole file name, not just 001. The dash works as a word divider, so I tend to use the convention of document-001 instead.

Oct 5, 2006 9:26 AM in response to Kappy

you can create such filenames using
Unix's special escape character, the backslash, or by
enclosing the filename in quotes. For example,
25\/02\/2006 will treat the forward slash as a
character in the filename rather than the standard
Unix path separator. Alternatively, '25/02/2006' or
"25/02/2006" will accomplish the same result. In
fact you need to enclose filenames with special
characters and spaces in quotes or use the backslash
before each character in order for Unix to treat the
filename correctly.

OSX Terminal won't let me create a file with a slash in the name whichever quoting method I use. Maybe a different shell would allow it. Maybe some version of Unix other than Darwin. Ah, the joys of Unix! One name, 523 operating systems, each one behaving slightly differently.

If it did create such a file, how would OSX handle the filename. If it substituted a colon, it might break a lot of Mac software. If it left it a slash, you could have two different Unix files that had the same Mac name, so OSX could not correctly convert the name back to Unix format.

Slashes in file names

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.