GetFolderItem and Exists

Am I missing something?
I thought if you issued a getFolderItem and the target file did not exist but the path to it did then the folder item would be created but the Exists property would be set to false. I am testing my app’s error handling and edited the file name but left the path valid and the GetFolderItem is being set to null.
I’m on macOs High Sierra and converted the app to 64bit.


A file does not exist at the designated folderitem unless you explicitly create one. I don’t understand what you are talking about the .exists property being set to false

Sorry didn’t make myself clear.

f = GetFolderItem(“Users/Jack/Documents/GiftAid/GiftAid2006-2007.sqlite”, FolderItem.PathTypeNative)
if f <> nil and not f.exists then …

In the above statement, the file exists so to test the error handling I change 2006 to 2008 which doesn’t exist. My understanding was that the above statement should have created the folderitem because the path is valid but should set the folderitem Exists property to false because the actual file doesn’t exist.

Hope this makes more sense.

That is not correct. As Roger said… if the file does not exist, YOU must create it… it is never created “automagically”
Besides… how would Xojo know WHAT KIND OF FILE to have created? A textfile, a Database, an Image?

f = GetFolderItem("Users/Jack/Documents/GiftAid/GiftAid2006-2007.sqlite", FolderItem.PathTypeNative)
if f <> nil and not f.exists then 
end if

And what if you really just want to know if a file exists? Would not be always handy if Xojo would automatically create such a file. :slight_smile:

I wasn’t trying to create the file and I’m not expecting Xojo to create it either … I expect it to be there. What I am doing to making sure it exists. My concern here is the difference in behaviour of GetFolderItem from what I expected. I expected a valid folderitem to be created but f.exists to be false. What I’m getting is F = NIL so the code you’re suggesting will never be executed. By folderitem here I’m taking about the Xojo control item, not the file on disk.

F=NIL indicates that the supplied path information does not resolve to a file path name that is VALID for the operating system. As in a file with that “name” cannnot be created.

try this

f = specialfolder.documents.child("GiftAid") // check if the sub directory exists before checking if a file within does
if f<>nil and f.exists then 
if f<>nil and f.exists then /// YOU REALLY DO HAVE A GOOD FILE
end if

That’s got it … that’s the behaviour I expected.
Thanks for your help.


BTW: in

f = GetFolderItem("Users/Jack/Documents/GiftAid/GiftAid2006-2007.sqlite", FolderItem.PathTypeNative)

the first slash before “Users” is missing. Therefore the path is illegal.

I had some code that was working for 10 years with this kind of line… and now suddenly its giving an error. So I have this problem too.