GetFolderItem Questions

Hello All,

For some reason, I have a nasty brain freeze with the whole use of GetFolderItem. I am sure it is quite simple, which is probably one reason I have been struggling with it! Wayne Golding was kind enough to provide insight into another GetFolderItem problem I had, and which answer I have used to try to understand this object more. I would respectfully suggest to Paul Lefebre that a larger section be devoted to this object in the help that he has been working on for Xojo. In the meantime, I was hoping to begin a conversation that myself and others might reference and/or join, to further our mutual understanding.

To begin with here are a few scenarios:

Debug Builds:
The current folder will, in my case, not work when in debug build mode:
Dim f As Folderitem = Getfolderitem("")
Since the default folder will be a temporary “debug” folder that is nicely deleted when the debug session is over.

So I used code like:
#If Debugbuild Then
#Else
#Endif

In the debug part, a path must be provided, other than the “” path.
#If Debugbuild Then
f = getfolderitem(“C:\MyAppFolder”)
#Else
f = getfolderitem("")
#Endif

Whether in a debug mode or not, one problem I have, is how to “add” onto the path:
f = getfolderitem.parent.child(“Data”)
The above code however, fails on compile - missing parameters.

Note:

  1. The desired path [excluding file name] is “C:\MyAppFolder\Data”
  2. Including file name could be something like “C:\MyAppFolder\Data\MyDatabase.db”

What would happen if there were an ini file, with the base path, but the file name left out since >1 files will be accessed from the same base folder?

**Sorry this was posted early than I wanted, in error… ***

GetFolderItem, by default, should be in relation to the folder your application executable is in… so if it’s in “C:\MyAppFolder” then using f = GetFolderItem(“test.dat”) will open “C:\MyAppFolder\test.dat”.

According to your notes, try:

f = GetFolderItem("data\\mydatabase.db")

Again, my apologies! I must have hit the wrong key(s) posting the conversation before I was ready - I had been saving it along the way!
Is there a more complete FolderItem reference (for dummies like me please) ?

Hi Eric,

Thank you for your rapid reply!

So what should be used, when the folder is not in the application folder?

Tim

Then use the full path where it is located… ie.:

f = GetFolderItem("c:\\some_other_folder\\mydatabase.db")

Thanks again Eric,

But what if you do not have the path as a string , or do not want to hard code the path? Just the raw code - lets go back to the a folder item that was previously, in code, obtained -

How to add a Child folder, and ultimately a file name to the GetFolderItem function request?

Hmmm… not sure what you’re asking, so I went back to your original post. In it, you specified that the following gave an error:

f = getfolderitem.parent.child(“Data”)

This is because you used .parent without referencing a path first. If you want the parent of the path your application is it, you’d use:

f = GetFolderItem("").parent

For what I think you want… you’ll need something like:

f = GetFolderItem("").child(“data”).child(“mydatabase.db”)

If this still isn’t the information you need, let me know… we’ll eventually get there. :slight_smile:

Hi Eric,
Yes, that does help. But in general, why the ("") before the .Parent?
My thought was that if [any] Parent has been gotten, why reference it again? Further if the parent is not the apps folder, then using the code ("") would not be appropriate.

For example, if the apps folder is c:\my app, but the current parent folder is c:\someotherfolder then using ("") would not work - correct? what would be appropriate? Again, code driven not hard coded, except as necessary of course.

Thank you again!
Tim

Tim, for your program to access a folder it must be one of the following

  1. relative to the executable’s folder (use GetFolderItem(""))
  2. in a system defined location (use SpecialFolder)
  3. in a fixed location (use GetFolderItem with a hard-coded path)
  4. selected by the user (use GetOpenFolderItem or OpenDialog)

GetFolderItem requires an argument. GetFolderItem.Parent is equivalent to GetFolderItem().Parent. The path is missing from the parens.

If your app is in C:\MyAppFolder, then GetFolderItem("") returns C:\MyAppFolder, and GetFolderItem("").Parent returns C:\.

For your debug question:

#if DebugBuild then f = getfolderitem("").Parent #else f = getfolderitem("") #endif
The debug app will be in c:\myappfolder\debug myapp\, so
getfolderitem("") --> c:\myappfolder\debug myapp\
getfolderitem("").Parent --> c:\myappfolder\

Tim

I see the GetFolderItem("").child(...) idiom quite a bit, but it’s wasteful. The better approach is just to pass the name of the child into GetFolderItem, like so:

f = GetFolderItem("data").child("mydatabase.db")

What do you do:
If a GetFolderItem has already been performed in some other area of code (and the folderitem variable is still in scope), but it is not certain what the last folder item obtained was?

In the case above, if I use the AbsolutePath, it may or may not include a file name. What is the correct procedure to exclude the file name, leaving then a known path only?

How to know when to use a Backslash at the end of a hard coded string, and when not to?

@Joe [quote]f = GetFolderItem(“data”).child(“mydatabase.db”)[/quote] So in this case, giving the whole path including the initial ("").Parent is not necessary? It is assumed?

Thanks again all.
Tim