NativePath x Absolutepath

Hello,

          I'm upgrading a software that use internally in my job before I wore a version of RealStudio 2011 r4.3 and this week bought the license Xojo 2014 r2, I'm replacing the code   [b].AbsolutePath[/b]   for  [b].NativePath[/b]   but when I do this I I have a message IOExeption error, but if I let on. AbsolutePath works perfectly. 

           I put the code and already advance that if I change the file location also gives error:

[quote]Dim file as FolderItem
dim valid as TextInputStream
dim Resultado as string

file=GetFolderItem(specialfolder.Desktop.child(“AAO”).Child(“01t”).NativePath)

if file<>nil then

valid = TextInputStream.Open(file)

Resultado=valid.ReadLine


window1.Label1.Text=Resultado

end if[/quote]

Thanks for any suggestions !

[quote=117147:@Paulo Vargas]Hello,

          I'm upgrading a software that use internally in my job before I wore a version of RealStudio 2011 r4.3 and this week bought the license Xojo 2014 r2, I'm replacing the code   [b].AbsolutePath[/b]   for  [b].NativePath[/b]   but when I do this I I have a message IOExeption error, but if I let on. AbsolutePath works perfectly. 

           I put the code and already advance that if I change the file location also gives error:

[/quote]

[quote]file=GetFolderItem(specialfolder.Desktop.child(“AAO”).Child(“01t”).NativePath)
[/quote]

You are confusing path and folderitem structure. Here is what you should do :

file = specialfolder.Desktop.child("AAO").Child("01t")

Hi Michel Bujardet,

          Ok, confusion may actually be my problem, but the issue is that in RS in 2011 and with Xojo [b]. Absulutepath[/b] works perfectly, do you have any explanation for it because I use this same code years?

Just to be clear, I use: file=GetFolderItem(specialfolder.Desktop.child(“AAO”).Child(“01t”).AsolutePath) and works Fine !

It may work fine, but your doing double the work. GetFolderItem() returns a FolderItem from a string. SpecialFolder..... returns a FolderItem also. So, what you are doing is:

  1. Getting a FolderItem: SpecialFolder.Desktop.Child().Child()
  2. Getting the string representation of that FolderItem (.AbsolutePath)
  3. Getting a FolderItem of the exact FolderItem you had in step 1 from a String (GetFolderItem)

So, as you can see, Steps 2 and 3 are not doing anything for you.

file = SpecialFolder.Desktop.Child("AAO").Child("01T")

And

file = GetFolderItem(SpecialFolder.Desktop.Child("AAO").Child("01T").NativePath)

Will result in an identical file object.

Now, be careful nesting your .Child() calls though, as any of those could return Nil. You should be doing something like:

Dim root As FolderItem = SpecialFolder.Desktop.Child("AAO") // Assuming the persons computer isn't toally messed up
If root <> Nil And root.Exists Then
  root = root.Child("01T")
  If root Is Nil Or Not root.Exists Then
    // Handle Error of 01T not existing
  End If
Else
  // Handle error of AAO not existing
End If

Oh, breaking the code out like that will allow you to more easily trap the IOException you are getting.

I never said it did not work in your previous code. It simply is unnecessary.

What you are doing with

 file=GetFolderItem(specialfolder.Desktop.child("AAO").Child("01t").AbsolutePath) 

is to convert a folderitem into a native path string to ask GetFolderItem to convert it back to a FolderItem.

Here is what you do in fact :

file = specialfolder.Desktop.child("AAO").Child("01t") f = GetFolderItem(f.NativePath) f.NativePath = "/Users/<username>/Desktop/AAO/01t"

All I am suggesting is that you stop using a double conversion and instead use the FolderItem structure :

file = specialfolder.Desktop.child("AAO").Child("01t")

That way you do not have to worry about AbsolutePath, NativePath, ShellPath or anything else. You directly tell your code where file is. Just try that in RS1011 and you will see it works perfectly without the convoluted double conversion scheme you where using.

Take the opportunity of this update to clean your code. The fact that it has worked for years does not mean that with your growing competence, you cannot use a better code.

Now, if you really insist on doing a double conversion, the reason it does not work is because you don’t tell getFolderItem the type of path you are using. Here is the corrected code :

file=GetFolderItem(specialfolder.Desktop.child("AAO").Child("01t").NativePath, FolderItem.PathTypeNative)

But I must insist. Use this and you will be fine :

file=specialfolder.Desktop.child("AAO").Child("01t")

Tanks Jeremy and Michel, helped a lot !