folderitem.child("abc") differences in iOS

In Xojo classic you were able to create a pointer to a virtual file using e.g.
dim f as folderItem = specialFolder.documents.child(“abc”)

if you looked at the contents of f they would be there, regardless of whether the file existed. e.g. f.displayName would show “abc”.

In iOS the same doesn’t work. Calling f.displayname results in an IOException if the file doesn’t actually exist. It seems as if the you can’t have reference to a virtual file.

Is this deliberate or a bug?

A bug I think - based on the notes to folderitem.exists: [quote]Exists As Boolean (read-only)
Indicates whether the FolderItem exists.

Notes
You can create a FolderItem that does not refer to actual existing file on disk. When you do so, this property returns False.[/quote]

Although using f.name does seem to give the right answer.

The documentation for Xojo.IO.FolderItem.Child says:

So this is a little confusing.

Another data point: on desktop, xojo.IO.FolderItem.DisplayName does not throw an exception.

I would not use DisplayName for a non existing yet file anyway. Name is the actual name of the future file. DisplayName results from an interpretation of that name according to locale. It probably needs the file to exist to do its magic. At least on iOS, which is notoriously less tolerant.

Michel

What you say makes some sense, though it means we would need to check for file.exists before examining file.displayName - which seems a little heavy.

In the manual it says [quote]Under Mac OS X, use DisplayName rather than Name when displaying the name of the item to the user.[/quote] but there is equivalent comment for iOS.

So perhaps I just put it down to platform inconsistencies?

Although they are cousins, iOS is much less tolerant than OS X.

It is not very difficult to have something that works in both instances.

Typing from XDC conference, top of my head :

function myDisplayName(f as folderItem) as Text if f.exists then return f.displayName else return f.name end if

[quote=290500:@Michel Bujardet]Although they are cousins, iOS is much less tolerant than OS X.

It is not very difficult to have something that works in both instances.

Typing from XDC conference, top of my head :

function myDisplayName(f as folderItem) as Text if f.exists then return f.displayName else return f.name end if[/quote]
Wrap that in a try-catch and you should be good to go