FolderItem.Directory shows as false for a folder

This is a folder that lives on my local drive, and it’s failing a simple test of FolderItem.Directory. Why would the value of that parameter appear as false, and why would the folder appear as non-existent? It’s clearly there, and it’s clearly a folder.

@Perry Paolantonio — A path like " Macintosh HD/…" is a relative path so its existence depends on which folder you gave as the parent folder.

But even with a native path like [quote]/Users/perry/Documents/BAG-TEST-FOLDER/Folder[/quote] the FolderItem.Directory shows as false and “Exists” shows as false as well.

I cannot reproduce this behaviour with a dir on my desktop

Catalina perhaps? Need to give app permission to access said folder?

which xojo version ?
on what OS ? and what version of said OS ?

That looks like you’re putting the entire path into the filename. What does the NativePath property say?

[quote=457403:@Norman Palardy]which xojo version ?
on what OS ? and what version of said OS ?[/quote]

MacOS X Mojave (10.4.4)
Xojo 2017 r3

would need to see the code you have as that should work correctly

  filePath = records.Field("mediaFilePath")
  thisfile = GetFolderItem( filePath )

Where “mediaFilePath” in the recordset is the path above: /Users/perry/Documents/BAG-TEST-FOLDER/Folder

If I specify FolderItem.PathTypeNative as a second argument in GetFolderItem, I get a nil FolderItem.

That’s correct. I’m passing it the native path: [quote]/Users/perry/Documents/BAG-TEST-FOLDER/Folder[/quote]

in the debugger, NativePath property: [quote]/Users/perry/Documents/Satchel/ :Users:perry:Documents:BAG-TEST-FOLDER:Folder[/quote]

If I call GetFolderItem with the path type specified: [quote]thisfile = GetFolderItem( filePath, FolderItem.PathTypeNative )[/quote]
…the resulting folderitem is nil.

Ok.
Try it properly:

[code]dim par as folderitem
dim chl as folderitem
par = specialfolder.documents.child(“BAG-TEST-FOLDER”)
if not par.exists then //should really check for nil here too
msgbox “No such parent folder: are those the right hyphens?”

else
chl = par.child(“Folder”)
if not chl.exists then //should really check for nil here too
msgbox “Folder does not exist”

else
msgbox “Folder exists”
end if
end if[/code]

This assumes they YOU are the user ‘perry’
/Users/perry/
If you are not that user, you may not have permissions to the folder

If true, that path is serioiusly messed up - you are mixing “:” and “/” characters. I wonder if you have a file named “:Users:perry:Documents:BAG-TEST-FOLDER:Folder” that is living inside the folder “/Users/perry/Documents/Satchel/” ?

[quote=457465:@Michael Diehr]If true, that path is serioiusly messed up - you are mixing “:” and “/” characters. I wonder if you have a file named “:Users:perry:Documents:BAG-TEST-FOLDER:Folder” that is living inside the folder “/Users/perry/Documents/Satchel/” ?
[/quote]

There is no file with that name in the folder. If I navigate to the folder in the command line and pwd, I get the exact path I pasted above: ‘/Users/perry/Documents/BAG-TEST-FOLDER/Folder’ – this is the path the OS reports. If I take the record set out of the equation, and set my filePath variable to that path, I get the same result, with the path to my application followed by the old-school colon-delimited mac path, under NativePath.

[quote=457461:@Jeff Tullin]Ok.
Try it properly:

[code]dim par as folderitem
dim chl as folderitem
par = specialfolder.documents.child(“BAG-TEST-FOLDER”)
if not par.exists then //should really check for nil here too
msgbox “No such parent folder: are those the right hyphens?”

else
chl = par.child(“Folder”)
if not chl.exists then //should really check for nil here too
msgbox “Folder does not exist”

else
msgbox “Folder exists”
end if
end if[/code]

This assumes they YOU are the user ‘perry’
/Users/perry/
If you are not that user, you may not have permissions to the folder[/quote]

I am that user and I have permissions.

I’m not sure how this solves my problem, and it seems to add an awful lot of overhead. The folder I’m running this on could easily have upwards of 300,000 files. Double calls to FolderItem seems like a bad idea in those cases.

[quote=457458:@Perry Paolantonio]That’s correct. I’m passing it the native path:

in the debugger, NativePath property:

If I call GetFolderItem with the path type specified:
…the resulting folderitem is nil.[/quote]
usually that indicates that something in the path doesnt exist

I suspect you aren’t actually giving it the native path you think. I think you’re giving it the path :Users:perry:Documents:BAG-TEST-FOLDER:Folder without realizing.

Bingo - Looking closely at the path from the record set, it’s adding a space at the head of the field. To confirm, I added a space to the beginning of a hardcoded path and get the same result.

Wrapping the record set field value in a trim() fixes it. But why is recordset adding these spaces? I stepped through the code and there is no space on the string I’m putting into my sqlite database, but it’s there on the output.

The issue turned out to be that the recordset was adding a space to the beginning of the path. Trimming that out solved the problem. Something inside Xojo (?) was generating the colon-delimited path because of that space.

well … when you put data IN it has a specific encoding for text
when you pull that data out it doesnt UNLESS you define it
and it you dont do that you can get all kinds of screwy things going

this is a great article about one of those effects you can see
https://blog.xojo.com/2013/08/20/why-are-there-diamonds-in-my-user-interface/