folderitem problems - help !

Hi,
the below method loads at startup a file named lastfile.txt that contains a single text line indicating the full path of a file to load.
I save my compiled app on dropbox and use it on two computers so, for obvious reasons, the file path contained inside lastfile.txt works only on one of the two computers and on the other one I get the error message: “exception message: the path passed into new Folderitem was invalid”.

I guess that it refers to the line hilited in bold, but I dont understand why since the part with IF g.exists should take care of “wrong paths”.

What am I missing here fellow coders ???
thanks

  'Tries to load lastfile.txt for reading the full path of the file to load 

  Dim F as  FolderItem
  Dim Fname as string
  Fname=left(app.ExecutableFile.nativepath,len(app.ExecutableFile.absolutepath)-4) ' getting the path of the libs folder
  fname=fname+" Libs/LastFile.TXT"  ' it's in the libs folders
  f=new FolderItem( Fname, folderitem.PathTypeAbsolute)
  
  If f.Exists Then
    // Be aware that TextInputStream.Open coud raise an exception
    Dim t As TextInputStream
    Try
      t = TextInputStream.Open(f)
      t.Encoding = Encodings.utf8
      dim Riga as string
      Riga= t.ReadAll
      
      dim G as FolderItem
  [b]    g=new FolderItem(trim(riga),folderitem.PathTypeAbsolute)    <<<<<<<----I suspect this line causes error when riga contains a wrong path[/b]
            
      if g.Exists then 'checks if exists, if not then kill file
        app.LoadFile trim(riga)' trim necessary otherwise wont read file path
      else
        f.Delete ' erase lastfile.TXT
      end if
      
    Catch e As IOException
      t.Close
      'cant read for some reason
    End Try
  else
    
 End If
  

You need to test for Nil before you test for Exists. A bad path could result in g being nil, which would cause an exception on if g.Exists.

Same thing. I still get the error:
An exception if class unsupported format exception was not handled. The application must shut down.
Exception message: the path passed into new Folderitem was invalid

??? What can it be ??

[quote=202506:@Horacio Vilches]Same thing. I still get the error:
An exception if class unsupported format exception was not handled. The application must shut down.
Exception message: the path passed into new Folderitem was invalid

??? What can it be ??[/quote]

Maybe your LIbs folder. Under Windows, a subdirectory is indicated by a backslash, not a slash as you did. Here it is, corrected :

Fname=left(app.ExecutableFile.nativepath,len(app.ExecutableFile.absolutepath)-4) ' getting the path of the libs folder fname=fname+" Libs\\LastFile.TXT" ' it's in the libs folders
Whenever you build a FolderItem from a path, you should test it is not nil. f.Exists is not enough there as well.

I fixed the slash but the same problem persists :-((((

This is pretty clear :

[quote]An exception if class unsupported format exception was not handled. The application must shut down.
Exception message: the path passed into new Folderitem was invalid[/quote]

The path is invalid.

It can be f, it can be g. And testing for nil won’t help, as the error happens in the construction.

Put a break like this before the new f :

Break f=new FolderItem( Fname, folderitem.PathTypeAbsolute)

Then go step by step until you encounter the error. That will give you the exact line where the error occurs.

I’m testing for BOTH NIL and exist and It’s also inside a Try-catch !

Also the error cannot be detected at design time because it’s related to a file that is saved on the libs folder hence it happens only
with the built exe files.
I’m afraid I’ll have to quit on this one :frowning:

[quote=202975:@Horacio Vilches]I’m testing for BOTH NIL and exist and It’s also inside a Try-catch !

Also the error cannot be detected at design time because it’s related to a file that is saved on the libs folder hence it happens only
with the built exe files.
I’m afraid I’ll have to quit on this one :-([/quote]

Before putting a Try Catch you need to know the exact error. What do you get in App.UnhandledException ?

What you get maybe related to DropBox.

Yes it is totally related to dropbox.
Anyways I just removed the “e as Ioexeption” so it catches the generic error, at least now it wont crush