# folderitem problems - help !

**URL:** <https://forum.xojo.com/t/folderitem-problems-help/25700>\
**Category:** General\
**Created:** [July 24, 2015, 9:59pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700 "2015-07-24T21:59:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [July 24, 2015, 9:59pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/1 "2015-07-24T21:59:42Z")

</div>

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

```auto
  '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
  
```

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [July 24, 2015, 10:11pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/2 "2015-07-24T22:11:48Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [July 25, 2015, 12:02pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/3 "2015-07-25T12:02:09Z")

</div>

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 ??

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 25, 2015, 12:38pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/4 "2015-07-25T12:38:02Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [July 25, 2015, 1:10pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/5 "2015-07-25T13:10:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 25, 2015, 1:25pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/6 "2015-07-25T13:25:26Z")

</div>

> [@202526:@Horacio Vilches](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [July 28, 2015, 10:26am UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/7 "2015-07-28T10:26:27Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 28, 2015, 10:35am UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/8 "2015-07-28T10:35:06Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![Horacio\_Vilches](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/ad7895/32.png) [@Horacio\_Vilches](https://forum.xojo.com/u/Horacio_Vilches)\
**Post date:** [July 28, 2015, 12:46pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/9 "2015-07-28T12:46:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:51pm UTC](https://forum.xojo.com/t/folderitem-problems-help/25700/10 "2020-10-29T17:51:47Z")

</div>


