File in Relative Path to App

I have a folder structure like this under OS X (I’m aware there it is different in Windows):

./myapp.bin
./proj/a1/fileA11.ext
./proj/a1/fileA12.ext
./proj/a2/fileA21.ext
and so on

I would like to check if fileA11 exists. So I played a lot with FolderItem and GetFolderItem without success. If I don’t add any path it works. Tried with .Child too without success.

Dim dbFile As FolderItem = dbFile = GetFolderItem(“proj/a1/file1.ext”)
If dbFile.Exists Then

End If

Check out http://documentation.xojo.com/index.php/Application.ExecutableFile .

As I see Dim dbFile As FolderItem = dbFile = GetFolderItem("") gives me the relative path to my app like /Users/user/My Xojo Projects/My Project/ (<-- here is myapp.bin, proj folder and so on)

[quote=88581:@Urs Jäggi]
./myapp.bin
./proj/a1/fileA11.ext
./proj/a1/fileA12.ext
./proj/a2/fileA21.ext
and so on

I would like to check if fileA11 exists. So I played a lot with FolderItem and GetFolderItem without success. If I don’t add any path it works. [/quote]

I assume by ./ you mean the folder in which your application is. Then in there you have proj, right ? Here is how you access fileA11.ext. Change f according to what you look for. Here is the code in a pushbutton action :

Sub Action() dim f as folderitem f = App.ExecutableFile.Parent.Parent.Parent.Parent msgbox f.shellpath f = f.child("proj").child("a1").child("fileA11.ext") if f.exists then msgbox f.shellpath+" exists" end if End Sub

Thank you.

Don’t understand the Parent.Parent.Parent.Parent not fully but I will sooner or later :slight_smile:

[quote=88594:@Urs Jäggi]Thank you.

Don’t understand the Parent.Parent.Parent.Parent not fully but I will sooner or later :)[/quote]

App.ExecutableFile points to the actual Unix executable program file inside the Mac App bundle. A Mac application looks like a file when it is in reality a folder with folders inside. Right click on your application, select Show Package Content and it opens the application bundle (folder).

App.ExecutableFile points to (relative to the app) /Contents/MacOS/. So here are the successive Parent, equivalent to cd … on the command line.

  • Parent of : Contents/MacOS/ ; cd …
  • Parent of Contents/MacOS/ : /Contents/ ; cd …
  • Parent of Contents : / (your Mac app bundle) ; cd …
  • Parent of the bundle : the folder in which you have placed your Mac app bundle that looks like a file.

There you have your four parents :slight_smile:

Ahh… I knew that actually but didn’t thought about that… Now I understand! Thank you!