How replace GetFolderItem with Folderitem.Constructor in this my example?

“GetFolderItem was deprecated in version 2019r2.
Please use Folderitem.Constructor as a replacement.”

How should the below code be written using the replacement, please?

Var f As FolderItem
f = GetFolderItem("C:\Users\Lennart\Documents\abc.pdf")
If f <>  Nil And f.Exists Then
  f.Open
End If
1 Like
Var f As New FolderItem("C:\Users\Lennart\Documents\abc.pdf")
If f <>  Nil And f.Exists Then
  f.Open
End If

Hm… Simple enough :slight_smile: Thanks Rick

1 Like

Should probably include the path type parameter as well

Var f As New FolderItem("C:\Users\Lennart\Documents\abc.pdf", Folderitem.PathModes.Native)
If f <>  Nil And f.Exists Then
  f.Open
End If

whether you include the last param about following aliases is probably not relevant on Windows

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

1 Like

To me the docs are wrong, the examples even reflect the use without a second mandatory parameter.

The real syntax seems like: FolderItem.Constructor(path as String [, pathMode as PathModes = FolderItem.Native [, followAlias as Boolean = true]])

1 Like

Oh I agree the docs are wrong
The second param does seem to be optional
What the default is is not noted

Edit : Ah
There are several constructors (more than documented)

 Public Sub Constructor(path As String, pathMode As Integer = 0)
 Public Sub Constructor(path As String, pathMode As PathModes, followAlias As Boolean = True)
 Public Sub Constructor(source As FolderItem)

so the example without the specified pathmode defaults to mode 0 which I have no idea what that means

   Native = 3
   Shell = 1
   URL = 2 
1 Like

If you just specify a String path and don’t specific a PathModes enum, then you’re actually calling a deprecated Constructor.

https://documentation.xojo.com/api/files/folderitem.html.Constructor(path_as_String,_PathType_as_Integer%3DPathTypeAbsolute)

What a sad mess. If we don’t receive a deprecation warning in the compiling report, it’s not deprecated, it’s a current feature. IF it is really deprecated, add a warning with a suggestion to the new use in the compiler list of errors and warnings.

1 Like

It is there if you turn on all deprecation warnings
and then analyze the project

Ok, I’ve found it. But it should be ON as Default since API2. It silently is doing unknown things now, like using a pathMode = 0.

I had deprecation warnings on. But there are 2 (now or we ever had it?). I needed to turn on the second one.

image

1 Like

This makes Norman’s addendum the current preferred way.

Wouldn’t passing False be the equivalent of the old GetTrueFolderItem? That is relevant on Windows.

I suppose that could be true
Good point