folderitem nil and exists checking

I have a doubt, may be it’s simple but can’t get it.
In Mac OS X If I try to get a folderitem like
Dim f as folderitem = getfolderitem(mydumbpath/:myfile)
and call f.exists it raises Nilobjectexception, therefore I have to ask first if f <> nil like
if f <> nil then
if f.exists then
end if
end if

Is there anyway to overload f.exists just to get false if nil or doesn’t exists without having to create additional condition ?

Your code try to access a file using an absolute path, and that’s why you probably get f = nil.
Always use the Child method of a folderItem like for example:

dim f as folderItem = SpecialFolder.Desktop.Child(“a folder on Desktop”).Child(“a file inside the folder”)

About your question, just use

if f <> nil and f.exists then
   // do something
end if

but if you really want a such method that return false if the file is nil, then you have to write one, since FolderItem.Exists is a property:

Function ExistsNotNIL(extends f as FolderItem) as Boolean
  return (f <> nil and f.exists)
End Function

with extends, I think the nilObjectException is raised before it’s called.

I made feature request 31205 to have the extends method being called without nil check, so the method can do it directly.

[quote=52427:@Christian Schmitz]Function ExistsNotNIL(extends f as FolderItem) as Boolean
return (f <> nil and f.exists)
End Function[/quote]

You are right Christian.

So, don’t use the extension method.

Thanks so much.

Is it possible that in previous RB versions f<>nil and f.exists raised the NilObjectException because f.exists was always checked ?

Not as far back as I can remember, and that’s pretty far back.

Thanks again, I was a bit confused about this, will use the double “and” checking.

The short evaluation was there in Realbasic 1.0 already. Never changed.