File FolderItem doesn't ??? exist

I have a line of code that should be detecting a folder that exists,
but doesn’t according to either the debugger on Windows 10 (debugger reports tsfb.Child(“PrefsFile”).exists = False) and does exist on my Mac (my program doesn’t crash).
I upgraded from 2014 to 2016 and it was a problem in both versions. [code]If tsfb.Child(“PrefsFile”).Exists = False Then
tsf = Nil
Else
tsf = tsfb.Child(“PrefsFile”)

			End If[/code]

Suggestions?

Super tripple double check the path of the item in the debugger to the path of the item you believe it’s pointing to.

What’s the code that defines tsfb and tsf?
(you should try useful variable names sometime)

may be you are missing second folderitem parameter

dim tsfb as Folderitem = GetFolderItem("/path/to/tsfb", FolderItem.PathTypeNative)
If tsfb <> Nil and tsfb.Exists Then
tsf = tsfb.Child("PrefsFile") 
If tsf <> Nil And tsf.Exists Then
 // do it
End If
End If

1: get it working on one platform before you waste time on the other
2: Its not a crash, its a nilobject exception. Your code should test for and trap this.
3: I bet that somewhere in your code you are creating a file path that is relative to the application. The paths aren’t the same in the debugger between windows and mac.
4: Dont use files located ‘next to the app’ (ie in the same folder) That definitely wont work when you try to deploy. Use Specialfolder.applicationdata children instead

5: (as Tim says) Super tripple double check the path of the item in the debugger to the path of the item you believe it’s pointing to. Because you almost certainly didnt.

Its your code, not the version of Xojo

Don’t ever use GetFolderItem unless you absolutely have to.

Sorry I wasn’t clear enough. My code does work on Mac currently, and used to work on my PC at some point in time. I’ve been working on this since 2005 and this segment for a few years back (2013 maybe). Again it worked. It’s okay if XOJO improves and I’m happy.

Absolutely. I cheated and have a lot of trys to add.

I’m not sure about relative as in object language concept. This might be the 2nd path the program uses. The first was identifying the path leading to this folder.

Somehow I got the next to the app right. It’s under/below the app in a folder called data. This is actually the first path.
I also should spend time moving stuff over to SpecialFolder. Later.

I’m not sure how I can check it deeper. I know the enclosing folder exists and the file does have the same name as in Windows Explorer.

For Tim Parnell

tsfb = GetFolderItem(ts, 3)//.Child("PrefsFile")

What other code can I use?
Also Tim’s name isn’t highlighted like in Facebook. How do I identify him.

No we’re talking about the path relativity, because that’s a huge part of GetFolderItem.

I doubt that, you’re having errors.

This is a major part of your problem. Make this your priority.

[quote=318185:@Arthur Gabhart]
I’m not sure how I can check it deeper. I know the enclosing folder exists and the file does have the same name as in Windows Explorer.[/quote]
Check the Native Path value versus the full path to the item you’re trying to locate.

@Arthur Gabhart
You asked the same 4 weeks ago and got many tips
(SpecialFolder.ApplicationData)

https://forum.xojo.com/38823-windows-getfolderitem-nilobjectexception-error

[quote]Somehow I got the next to the app right. It’s under/below the app in a folder called data. This is actually the first path.
I also should spend time moving stuff over to SpecialFolder. Later.[/quote]

Thats not getting it right.
Its the whole reason why ‘it works’ on one platform and not on the other.
data folder is not where you think it is.

You start somewhere by using GetFolderitem("") I suspect
Then you just save a file without a path, or as a child of that .
Thats ‘next to the app’
Thats bad news, don’t do that, for all the reasons in this post and your others. Change it now.

When you run in debug mode, paths are different on PC and Mac.
The file isnt where you think it is, and using the debugger you can look at the whole path of the file… you will find there is an extra folder name in there which you dont expect

That doesn’t happen if your files are in Application Support folder.
Change it now.

link text

[quote=318186:@Tim Parnell]No we’re talking about the path relativity, because that’s a huge part of GetFolderItem.

I doubt that, you’re having errors.

This is a major part of your problem. Make this your priority.

Check the Native Path value versus the full path to the item you’re trying to locate.[/quote]
The above image is the path from Windows Explorer. It matches the path. Also when I check paths in the debugger they are the same.

What else is good at identifying a path? GetTrueFolderItem?

Yes I did use the “” to get my first path. And that’s (I think) what the path for the PrefsFile is. It is according to the debugger. So no extra folder like debugger. The “iniPaths.ini” has a getfolderitem and it has the same path and paths (native, etc)

rf = GetFolderItem("") IniPath = rf.Child("Data").Child("iniPaths.ini")
Is there a good explanation of setting up Special Folders? I am not sure what I need to or can include.

https://forum.xojo.com/conversation/post/316705

When it comes to FolderItem if you don’t start with SpecialFolder or a Open/Save dialog, you’re asking for trouble.
If you’re saving paths from user input, use http://documentation.xojo.com/index.php/FolderItem.GetSaveInfo to store it.

http://documentation.xojo.com/index.php/SpecialFolder - it’s just a bunch of pre-existing locations to work with.

I would recommend using my module over what Axel linked. The less you have to maintain, the easier your job will be.

But the choice is yours.

Yes. I got that, but I am looking for information on other things, like what actually goes in a preferences file.
Another problem is does it go in a folder of my creation or Windows/Apple?

My module takes care of that automatically, TPSF.AppSupport returns a FolderItem child of the application data folder that is set up properly for Mac / Windows. All you have to do is check if it exists and create it if not.

From your screenshot:

mainfolder = Specialfolder.Documents.child(“Basic Programming”)
reviewcardsfolder = mainfolder.child(“ReviewCards”)
Datafolder = reviewcardsfolder.child(“Data”)
Databasefolder = Datafolder.child(“Base”)
prefsfile = Databasefolder.child(“Prefsfile”)

if you dont know, you dont need one.
Color selections, last window sizes, language preference, question difficulty… anything that you want the program to remember when you come back to it as a user tomorrow.

[quote=318206:@Tim Parnell]When it comes to FolderItem if you don’t start with SpecialFolder or a Open/Save dialog, you’re asking for trouble.
If you’re saving paths from user input, use http://documentation.xojo.com/index.php/FolderItem.GetSaveInfo to store it.
.[/quote]
I created the super folder (Base) with my program and a dialog. I can’t locate the actual line I used but it’s there.
The program does use GetSaveInfo. I just confirmed.

Thanks for the location to your program Tim.

Thanks @[quote=318211:@Jeff Tullin]From your screenshot:
It will help soon.

[quote=251266:@Norman Palardy]RE : GetFolderItem("", FolderItem.PathTypeNative)
“” is a relative path which you cannot use with PathTypeNative[/quote]
How do I convert a relative to native path?

@Tim Parnell

I added your TPSF to this Demo for getting SpecialFolder Paths in Linux
(There are problems when the Folder Names are translated)

https://www.dropbox.com/s/4ksj83z3n9xfhqu/TPSF_2.zip?dl=1

TPSF Button should work on all OS

Thanks, I’ll try to get the changes merged in soon :slight_smile:

Edit: Oh, I thought you added a bunch of linux paths. I know there’s no linux support on the module yet.