I want to do something like this, without having to provide the absolute file path. while debugging:
Var Dingus As Thing
Var f As FolderItem("Folder_that_contains_xojo_project_file/my_file_of_interest")
Dingus=Thing.load(f)
As far as I can tell from documentation (and searching the forums), you can’t reference the folder containing the .xojo_binary_project file using child or parent or specialfolder.
Thus, I am pretty sure I have missed something simple.
var f as FolderItem = app.ExecutableFile.Parent.Child("WTFdb1.sqlite3")
app.ExecutableFile points to the executable
app.ExecutableFile.Parent is the folder the executable is in
app.ExecutableFile.Parent.Child() refers to a file next to the app
But shouldn’t a database file be in SpecialFolder.Resources? Or SpecialFolder.ApplicationData?
Pretty sure we have seen cases where having the db in resources alone stops it working as that location is read-only.
As far as I can tell from documentation (and searching the forums), you can’t reference the folder containing the .xojo_binary_project file using child or parent or specialfolder.
The xojo binary file is where your source code is.
When you run in debug, there are a variety of places where the debugging executable could be generated, and they won’t all be in the same folder as the xojo binary file.
So ‘local to me’ will not work.
Even when debugging, it is best to have your database file in
applicationdata.child(“mycompany”).child(“mydatabase”)
When distributing, create one there if it is missing at startup.
If it has to ‘arrive’ populated, bundle it into resourses and copy the file there at startup if missing.
That way, the code that finds and uses it when debugging is the exact same code that finds and uses it in a compiled app, and you dont have to use IF statements to handle different paths for release and debug
As far as I can tell, it’s you who started to discuss about a database file
As Jeff said, the location of the project file can be arbitrary located in regard to the debugged app.
In the Xojo IDE, you can specify the debug folder to use. If, say, you select the temporary items folder as the destination, how is the file system (or operating system) supposed to make a relation between a running app and a Xojo project file? Only the Xojo IDE knows that this running app is related to that project file, and there’s no OS API to provide such information on behalf of Xojo.
Neither of you are wrong. I am trying to access the db and some photos in a folder during the debug runs. I will keep using the absolute file paths until I near the first actual build.
This is a hobby project. I really appreciate you all taking time to help out.
Then you may just use the absolute path as you’re already doing, or start with app.ExecutableFile and use “parent” and “child” methods to access related folders.
app.ExecutableFile points to “…/YourAppName.app/Contents/MacOS/YourAppName”, so with using app.ExecutableFile.Parent.Parent.Parent.Parent, you’re accessing the folder containing your “.app” bundle. From that point, it’s up to you to move up and down to the folders hierarchy. Just be aware, if you ever move the debug app, the path will break.