GetFolderItem ?

Hello,
Windows 10 / XOJO 2019r31

Following method I use in XOJO 2018r4 to return the folder in which the debugbuild run

Var f As FolderItem = GetFolderItem("")
#If DebugBuild Then f = f.Parent
Return f

In XOJO 2019r31 (API2) GetFolderItem is deprecated.
In the doc they say : please ues FolderItem.Constructor as a replacement.
The example in the API2 doc does not has any solution for me.

How should my code be in API2 ?

Regards
Etienne

The example in the docs for the Consructor that takes a string is

So replace that line of code with

Var f as new FolderItem("")

Note that it isn’t clear whether the second parameter pathMode as PathModes is required. If so, try FolderItem.PathMode.Native

Thanks Tim.
It works.

[quote=495402:@Tim Hare]The example in the docs for the Consructor that takes a string is

So replace that line of code with

Var f as new FolderItem("")

Note that it isn’t clear whether the second parameter pathMode as PathModes is required. If so, try FolderItem.PathMode.Native[/quote]

Hi Tim, I have a question, I use Getfolderitem a lot too, how would these codes look for example ?

f=getfolderitem("").child("Names")

And this other search in a cell of the listbox the path

f2=GetFolderItem(filelist3.cell(filelist3.listindex,3)+filelist3.cell(filelist3.listindex,0)) textnovo=f2.NativePath

Tanks in advance

You’ll have to break this into 2 lines

f = new FolderItem("")
f = f.child("Names")
f2=new FolderItem(filelist3.cell(filelist3.listindex,3)+filelist3.cell(filelist3.listindex,0), FolderItem.PathMode.Native)

[quote=495432:@Tim Hare]You’ll have to break this into 2 lines

f = new FolderItem("")
f = f.child(“Names”)[/quote]

ok, and if i need more subfolders or files into subfolder I put like this :

f = new FolderItem("") f = f.child("Names").child("Image.png")

would that be Tim ?

I’ve never liked the concept of GetFolderItem("") and have always used App.ExecutableFile.Parent instead to get the working folder. Using this method f = App.ExecutableFile.Parent.Child("Names") works and to me is more obvious/readable.

WOW have I been wrong for the last 3 years programming in XOJO ???

I thought that this method returned me the path for my debugfolder

Var f As FolderItem = GetFolderItem("")
#If DebugBuild Then f = f.Parent
Return f

results in f.NativePath = D:\XOJO-Projects\XOJO_2019r31\MMLite\00 MMLite\
This is NOT the correct path for my debugfolder

Var f As New FolderItem("")
#If DebugBuild Then f = App.ExecutableFile.Parent
Return f

results in f.NativePath = D:\XOJO-Projects\XOJO_2019r31\MMLite\00 MMLite\DebugMMLite\
This likes more correct to me

How come that it worked with the first code too ?
The folders necessary for my program are still in the first folder, and it would even work without the copyfiles in Build Settings I think.

Thanks for the tip Wayne.

Those 2 sets of code have different purposes. If you just want the debug folder - the folder where your app is currently running - the following should be equivalent (on Windows at least):

GetFolderItem("")
New FolderItem("")
App.ExecutableFile.Parent

This code

Var f As FolderItem = GetFolderItem("")
#If DebugBuild Then f = f.Parent
Return f

is intended to get the folder where the project resides, not where the debug folder is. This became necessary when the debug location was changed to be a subfolder of the project folder.

Keep in mind that this probably doesn’t work on macOS. As I recall, this points to a file within the bundle and you need to use

App.ExecutableFile.Parent.Parent.Parent // cant remember if it’s 3 or 4