File name with / on Mac

On Mac, I have a folderitem var MyItem which point to a file which name contains “/” : “My File/slash.txt”.

MessageBox MyItem.NativePath + endofline + MyItem.Name

I obtain

/Volumes/MBtom-HD2/Tampon/My File/slash.txt My File:slash.txt

Is it normal ? Do I have to myself replace “:” by “/” ? I read the FolderItem Documentation but I didn’t see anything about that.
If I do :

MyItem2 = MyItem.Parent.Child(MyItem.Name)

I don’t get back to my original item, the item obtained doesn’t exists !!!

I dont follow
if you have the full native path already does the Folderitem constructor that takes a native path not work to get you that item ?
you should not have to manipulate the path or item name at all

I remember having to deal with files which had a “:” in the name. As far as I remember what you see is correct. In general names with / and : are a bad idea on macOS.

Here is the Feedback case I made: . A subtle difference between APIs 1 and 2.

I select a file with DropObject or with “Dim CeDialog as OpenFileDialog”. I obtain a folderitem MyItem. If I display the path or the name of this item, the “/” in its name is replaced by “:”.
I will have a look to the feedback.
Thank you Norman and Beatrix. We are agree it’s a bug, aren’t we?

Edit : I can’t find the FeedBack.

HOW are you displaying this? the various properties of FOLDERITEM display in different ways, some with “:” some with “/” it is important to know the purpose for each one.

For the test, I simply do :

MessageBox h_Elt.NativePath + EndOfLine + h_Elt.Name

But it’s the same if I display the file path and the file name in a ListBox.
No matter how I obtain the FolderItem ( as I said with a drag/drop on a dropobject event or with a OpenFileDialog .
I’m reviewing all my codes to remove all old API instruction, I don’t have any alert remaining, I’m full API2.
I’m under Mac OS Mojave.

Under the hood, Apple converts the “/” to “:” in the Finder APIs. If you look at the folder content in the Terminal using the BSD tools (ls, stat, etc.), you’ll see the : displayed -

In reality, you should stay away from these special characters in file names for sanity on ALL systems:

~ ` @ # $ % ^ & * ( ) { } [ ] | \\ < > : ; " ' / ?

And, then be aware of them so that your app can handle them once it is available in user-land.

[quote=483427:@Tim Jones]~ ` @ # $ % ^ & * ( ) { } [ ] | \\ < > : ; " ' / ?

Interesting! I have a slightly different list (that includes + and =).

I’m curious if any of the ones on your list are a problem only on Linux? My app is strictly macOS and Windows.

Slash is the only prohibited character for Unix files and folders, but not for Finder.

When OS X came to be, users already had files coming from MacOS (not based on uUnix like macOS 10.xx) which may contain the forward slash symbol used by Unix as separator.

So Finder will let you create and use file names with the forward slash in them, but on the Unix side, as seen in Terminal for instance, forward slash / will be replaced by a colon, which for the Finder is a prohibited character.

If you type this in Terminal:

echo test > tralala:tsoin.txt

And type ls, you will see your file tralala:tsoin.txt has been created.

You will get the following file in Finder : tralala/tsoin.txt

In practice, it is probably a good idea to stay away from forward slash in file and folder names.

I said a wrong thing, if I do:

MyItem2 = MyItem.Parent.Child(MyItem.Name)

with a path containing a (or many) “/” it works. If I display the path in a MessageBox the / are replaced by : but it works as usual in code.
And I notice that in SaveFileDialog , if I send a SuggestedFileName containing / (then displayed : in MessageBox) it is displayed with / in the SaveBox when we run the program. Then sometimes it is automatically manage, sometimes not.

I simply created a Method .GetName which do FolderItem.Name.CetElt.Name.ReplaceAll(":", “/”) when I want to display a FileName. I did the same but a little complicate to display a path.

Why do you insist on managing that kind of file name ? Do you actually expect many users will want a forward slash in their file name ?

This happens endlessly in the media and entertainment industry.

There are other entries, but most modern platforms can manipulate them.

In the old days, the “+” character had a special file “type” indicator for files on pTX and HP-UX (contiguous file), while even “=” was used to specify a sparse file or an extended concatenation.

One of my program synchronise files then it may see file with / . I had one myself, I was lucky it was in my test folder then I discovered this problem.
When I name file with date, I display “yyyymmdd MyName.pdf”, I don’t use / , neither than - , but people may use them.
Another program allow to rename file. If I want to rename a file, I have to :

MyFile.Name = TextFieldNouvName.Value.ReplaceAll("/",":").
If the TextField contains a / the file is not renamed.
I could not allow the user to rename file with a / but I’m sure I will receive many request email.

I have a question, I use a MacBookPro with a SSD under Mojave. Does this change in Finder (replace / by :slight_smile: exists since Mojave, a previous system? Or does it exist since APFS (and not on HFS) ? I have an old Mac El Capitan with HFS drive but I’m not at home and I can’t do the Terminal test with ls command.

That goes alllllll the way back. It’s not new to OS X.


El Capitan / actual Firefox:

No later than some days ago, I saved a SP (45 RPM vinyl) cover using this file name:
The Beatles - Hey Jude b/w Revolution - Apple .png

The slash was replaced by a space. In the Finder, I replaced the space with a slash and it stays in the file name.

On some application ‘:’ is replaced by ‘-’, but not in the Finder who reject it issuing an error dialog and reverting the file name to its previous value.

Now, I avoid non a-z / 0-9 characters (and eventually a space or more) in Xojo projects, always starting a project name with a character (not a number). This recalls me something… (Oh ! the Apple II syntax !)
It started when I had serious troubles with a project and that was not the problem, but this name (with special characters) or another…

Windows has more forbidden characters than macOS, so that means a lot of punctuation marks (including /) are a problem. And yes, my users like a lot of punctuation in their file names. Look at that list of characters (~ ` @ # $ % ^ & * ( ) { } | \ < > : ; " ’ / ?+) and then consider filenames such as “Work Notes: Friday” or “Budget $$ & Crew Hours” or “Meeting @ Theatre 4/12/20” or “Cue List (Revised)” or “Mack & Mabel Script” or “Screwy Label (!*$@!!).lwl”. The list goes on and on.

Lightwright data files are a zipped folder, inside that folder are a lot of files and folders that that have names determined by the user (pictures, labels, etc.). Everything is OK as long as the user opening the data file is on the same platform that it was saved on, but if you save a file on Mac (with its liberal character allowances) and then try to open it on Windows (where one of those file names inside the data folder is suddenly illegal), you’re hosed when unzipping. The user can’t access the data they saved. And yes, I have users who use one platform at home and the other at the theater.

So I have to screen the name of every file a user saves inside the data file, to make sure that they’ll be able to open it later, on both macOS and Windows. was so much simpler…:frowning: