Retaining FolderItem for File on External Drive

The user chooses a location on an external (or network drive) and I retain that as a FolderItem. Later that drive is disconnected and then reconnected. The FolderItem no longer points to a valid location.

Is this a known issue?

Is there a workaround?

The only one I can think of is if the FolderItem appears invalid, create another one based on the absolute path and see if that one is valid. Something unnerving about using absolute paths…

do you use the new framework folderitem and which xojo version do you have ?

Old framework. Xojo 2015 r4

[quote=240868:@Stephen Dodd]The user chooses a location on an external (or network drive) and I retain that as a FolderItem. Later that drive is disconnected and then reconnected. The FolderItem no longer points to a valid location.

Is this a known issue?

Is there a workaround?

The only one I can think of is if the FolderItem appears invalid, create another one based on the absolute path and see if that one is valid. Something unnerving about using absolute paths…[/quote]

It is always a problem when a resource disappears and comes back while an app runs.

I believe the folderItem has to deal with the way the system views a particular resource. Possibly it has a handle to that particular resource, that will necessarily be different when the drive comes back.

I would rather save the shellpath somewhere, and recreate the folderItem from that if it becomes nil. Don’t like native path. Never use it.

[quote=240868:@Stephen Dodd]The user chooses a location on an external (or network drive) and I retain that as a FolderItem. Later that drive is disconnected and then reconnected. The FolderItem no longer points to a valid location.

Is this a known issue?
[/quote]
Yes
On OS X or Linux the drive COULD be remounted at a different spot (literally with a different name etc) or manually and mounted to a different location in the overall file system

Not really - if you hold on to a folderitem there’s no “fix” except to NOT hold a folderitem
Hold on to its path , and URL path etc

[quote=240868:@Stephen Dodd]
The only one I can think of is if the FolderItem appears invalid, create another one based on the absolute path and see if that one is valid. Something unnerving about using absolute paths…[/quote]
And therein lies the issue I know of - you cant tell if its invalid
Pretty sure I filed a bug report as this also affects the IDE if you have a project on an external drive and then dismount that drive (deliberately or not) the folder item instance still exists but checking almost any property that could tell you that its valid will cause a crash
I know there’s this one <https://xojo.com/issue/14559>

On OS X you could use File System Events to basically watch drives and then invalidate any folder items you hold on to when a drive is dismounted
I’m sure Windows has something like this as well

Wow. Thanks Norman. That’s handy to know.

So, if you used FolderItem.GetSaveInfo to construct another folderItem, would it still point to the “wrong” location?

Save info on OS X is a damned site smarter as it does NOT rely on the mounted path :slight_smile:
It’s basically an alias inside.