Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automatic handling of special characters in filenames System
I used to love the fact that I could put just about any character in a file name is OS 9. With UNIX as a base, it appears that there are a few restrictions to naming files.

I know that in Windows (at least NT), if you use illegal characters in a file name, you will get a cryptic message about saving the file (can't remember what it is now...I try to forget I have to use 'doze at work).

I just noticed today, saving a web page out of Safari onto my iDisk, that when I try to put in a forward slash (/), Jaguar automatically changes that to a dash (-) in real time as I'm typing it! Personally I like that much better than having to figure out if there is some problem other than a simple character change.
    •    
  • Currently 1.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[11,017 views]  

Automatic handling of special characters in filenames | 6 comments | Create New Account
Click here to return to the 'Automatic handling of special characters in filenames' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Hm.
Authored by: mweissen on Feb 05, '03 12:56:47PM

This feature has been part of Mac OS since day one, the only difference being that file paths now use slash instead of colon, so it's the slash character that's affected in OS X. I remember seeing it in OS 7 some ten years ago.



[ Reply to This | # ]
Various characters to watch for...
Authored by: mholve on Feb 05, '03 03:55:13PM

Don't use wildcards like "?" and "*" if you can help it, don't use the "/" (forward slash) as it's a directory under Unix, don't start filenames with a "." because then an "ls" at the command line won't see it without adding some flags (try "ls -ld ~/.*" for example). If you work with just Aqua (the GUI) it might not matter so much, but it'll make life easier in the Terminal.



[ Reply to This | # ]
Characters and filenames
Authored by: miggins on Feb 05, '03 08:03:05PM

Mac filenames can have any character except : (colon) which is the path seperator. Unix filenames can have any character except / (slash) which is the path seperator. Windows plays it a bit safer - you can't have any of these \\ / : * ? " < > | in a filename.

In Mac OS X, if you use HFS+ the seperator is : but from unix programs (like Terminal) it will be auto translated to / for those programs.

This is all good, but I wish that the smb mounting feature in Mac OS X would translate or strip out the characters that Windows doesn't like when you copy files. What happens now is you drag a folder to a Windows drive and it just gets part way through and says "something could not be found" and stops. Very annoying.

Actually it would be best if you could choose a connection mode when you mount an smb drive - 1. store everything, which would use ._ files and encode filenames somehow so that they look strange in Windows but keep the special characters in Mac OS X.
2. compatible mode, which would strip resource fork and metadata from the file and strip special characters from the filename.



[ Reply to This | # ]
You can use /
Authored by: vonleigh on Feb 06, '03 07:54:28AM

Hello,

Did a quick test and got interesting results: Create a new folder, name the folder something with a forward slash in the name. For some reason it will allow you to do it (I have a recollection of the finder not allowing you to before, but I'm not sure).

If you look at the same file from the terminal, the forward slash will display as a colon. For those of you that don't know, there's a translation that goes on automatically from colon to slash, since HFS uses colons to separate folders and BSD uses /. You can read about it in a great paper by Wilfredo Sánchez:

<http://www.mit.edu/people/wsanchez/papers/USENIX_2000/>

Can anyone test OS X prior to Jaguar to see if it allowed you to use slashes? I wonder what the reasoning is behind it to allow you to use it now.


v



[ Reply to This | # ]
You can use /
Authored by: wtp on Feb 06, '03 10:38:25AM

Finder's actually displaying a ":".

In the bad old days of non-Unixy MacOS, a colon was used as the `path separator'. Unix has always used the forward slash as it's path separator, and so Mac users saw a change with MacOS X. To hide this change from the users, and confuse them, Finder.app shows files with ":" in their names as files with "/" in their names. If you open Terminal.app, however, ls will show you the true name. If you type "touch foo:bar" on the command line, it will create a file called foo:bar... look at that file in the Finder: "foo/bar".

The old MacOS accepted more characters in its filenames than Windows did, but not as much as Unix does. Unix only forbids the slash and ASCII NULL (it could be argued that the filesystem allows ASCII NULL, but Unix (and C!) really does not). Unix allows newlines, form feeds and other crazy things in its filenames. It is yet to be determined if these extra characters are a Big Mistake or a Bad Idea. In practice, shell wildcards, quotes, and even spaces are a little bit of a pain to use on the command line, and should be discouraged. So now, with OS X, Mac Users have greater flexibility, at the cost of some extra complexity. The choice is ultimately yours as to what you name your files, and how you want to shoot yourself in the foot. Just no "/" -- okay? :-)

[ Reply to This | # ]

You can use /
Authored by: sinanakay on May 03, '03 04:36:18AM

Hello everybody

I know there must be someone out there who already solved this problem:

I have thousands of filenames with "/" in them which I want to convert to "-" there must be a way to do that in terminal. Applescript shipped with the mac is not help.
TIA for any hints and pointers

Sinan



[ Reply to This | # ]