New API folderitem

When adapting a project to the new API the only doubt (…) is on FolderItems

Old API

dim f as FolderItem  = GetFolderItem(Prefs.DefaultFolder, FolderItem.PathTypeNative)

you get: " Warning: GetFolderItem is deprecated. You should use FolderItem.Constructor(path As String, pathMode As PathModes) instead."

New API

dim f as folderitem = FolderItem.Constructor(Prefs.DefaultFolder, FolderItem.PathTypeNative)

you get: “Error: There is more than one method with this name but this does not match any of the available signatures.”

Some help please

Assuming Prefs.defaultFolder is a String, the New API Folderitem should look like

var f as new FolderItem(Prefs.DefaultFolder,FolderItem.PathTypeNative)

or

var f as  FolderItem = new FolderItem(Prefs.DefaultFolder,FolderItem.PathTypeNative)

Me too I am struggling with the ‘FolderItem.Constructor’ replacing the Deprecated ‘GetFolderItem’.

In my old code :
OpenDocument is a String containing the Path for a loaded file (D:\MyMusic\Etienne\Perferct.mid)
f is declared as a folderitem
old code is : f = GetFolderItem(OpenDocument)
This works very well, but in 2019r2 API2 ‘GetFolderItem’ is deprecated.

What code should I use in API2 for replacing my : f = GetFolderItem(OpenDocument)
Thanks

Regards
Etienne

I’m confused because the warning say we must use FolderItem.Constructor

And the code follows as

[code]if f <> nil and f.Exists then

dim dbFile as FolderItem = f.Child(s)[/code]

So the file is created inside the Folder, the use of New cretes another confusio. The help, on FolderItem, is not very clarifying.

the constructor just have more arguments in case of path is used

'Dim f As New FolderItem("C:\\Temp\\Test.txt") Dim f As New FolderItem("C:\\Temp\\Test.txt",FolderItem.PathModes.Native) System.DebugLog(Str(f.Exists))

But now we must use the New to get a folderItem?

Edwin

you said “the New API Folderitem should look like”

var f as new FolderItem(Prefs.DefaultFolder,FolderItem.PathTypeNative)

or

var f as  FolderItem = new FolderItem(Prefs.DefaultFolder,FolderItem.PathTypeNative)

But this give the following warning:
Warning: Constructor is deprecated. You should use Contructor(path As String, pathMode As PathModes, followAlias As Boolean) instead.

This gives the same warning
“Warning: Constructor is deprecated. You should use Contructor(path As String, pathMode As PathModes, followAlias As Boolean) instead.”

[quote]GetFolderItem is deprecated. You should use FolderItem.Constructor(path As String, pathMode As PathModes) instead.
[/quote]

simply means

change getFolderItem(…) to new FolderItem(…)

The constructor method is what you get when you NEW something, if it can take parameters.

eg

x = new myClass x = new myClass( 29) x = new myClass (somevariable, someinteger)

All of thes call a constructor.. a class can have several constructors… the actual one called is determined by the parameters you pass.
But you do not have to use the word Constructor

[quote=458159:@Jeff Tullin]simply means

change getFolderItem(…) to new FolderItem(…)

The constructor method is what you get when you NEW something, if it can take parameters.

eg

x = new myClass x = new myClass( 29) x = new myClass (somevariable, someinteger)

All of thes call a constructor.. a class can have several constructors… the actual one called is determined by the parameters you pass.
But you do not have to use the word Constructor[/quote]

I’m not able to found the correct spelling

give the warning

Gives an error

doing as you suggested change getFolderItem(…) to [b]new FolderItem(…)[/b
Shows a a warning:
Warning: Constructor is deprecated. You should use Contructor(path As String, pathMode As PathModes, followAlias As Boolean) instead.

The same for

What is “Prefs.DefaultFolder”? If it’s a string then

dim f as new FolderItem(Prefs.DefaultFolder,FolderItem.PathTypeNative)

should work (down with var!!!). I also was confused a couple of times with the new documentation between what is meant as literal and what is not.

Yes, Prefs.DefaultFolder is a string
But I get the warnig:

Warning: Constructor is deprecated. You should use Contructor(path As String, pathMode As PathModes, followAlias As Boolean) instead.

Even (just to analyze)

dim f as new FolderItem("hello",FolderItem.PathTypeNative)

Gives the same warning
I just created a new project with a line of code

dim f as new FolderItem("hello",FolderItem.PathTypeNative)

and get the warning

In fact, all examples on FolderItem help

give the warning or…

others, simple give an error

Syntax error
Var f As new FolderItem("").Parent

This is the correct code:

dim f as new FolderItem("hello",FolderItem.PathModes.Native, false)

a) You need to use PathModes.
b) You need the third parameter.

Just look at the Documentation… There is even an example provided:

New FolderItem("/home/path/with space", FolderItem.PathModes.Native)

Note: FolderItem.PathTypeNative is now in API 2: FolderItem.PathModes.Native

Oh - @Beatrix Willius has been faster once again today :wink:

No, you don’t. It’s optional. This doesn’t give a warning:

Dim myFile As FolderItem = New FolderItem("/home/path/with space", FolderItem.PathModes.Native)

[quote=458168:@Beatrix Willius]This is the correct code:

dim f as new FolderItem("hello",FolderItem.PathModes.Native, false)

a) You need to use PathModes.
b) You need the third parameter.[/quote]

Thans Beatrix, this is the true code to replace old one.
Probably the help on FolderItem should be improved…

Looking all the reply’s I found my solution for my FolderItem problem.

Instead of the deprecated code :

Var OpenDocument As String = "D:\\MyMusic\\Etienne\\Hello.mid"
Var f As FolderItem
f = GetFolderItem(OpenDocument)

I need to use :

Var OpenDocument As String = "D:\\MyMusic\\Etienne\\Hello.mid"
Var f As FolderItem
f = New FolderItem(OpenDocument, FolderItem.PathModes.Native)

Or :

Var OpenDocument As String = "D:\\MyMusic\\Etienne\\Hello.mid"
Var f As New FolderItem(OpenDocument, FolderItem.PathModes.Native)

Thanks everybody
Regards
Etienne

One little question :
What does the last optional parameter ‘False’ or ‘True’ means.

Regards
Etienne

[quote=458178:@Volbragt Etienne]One little question :
What does the last optional parameter ‘False’ or ‘True’ means.

Regards
Etienne[/quote]
If the file is a symbolic link/shortcut/alias, you’ll get the actual file if you pass true. If you pass false, you’ll instead get the file that the symbolic link/short/alias points too.

https://documentation.xojo.com/api/files/folderitem.html.Constructor(path_as_String,_pathMode_as_FolderItem.PathModes,followAlias_as_Boolean%3D_true)

i think you missed this warning before
“… PathTypeNative is deprecated. You should use PathModes.Native instead …”