Issue with FolderItem

Good Evening

Might be because it is late, but I can’t seem to find why this is not working:

Dim f As FolderItem f = SpecialFolder.Desktop.Child(ResourcesFolderName).Child(PreferencesFolderName).Child(PreferencesFileName)

When I run this, I get a NilObjectException. I tried replacing the constants with strings and got the same result. If I delete one of the Child folder, it works… I guess I am missing something simple, but I can’t figure out what.




f = SpecialFolder.Desktop.Child(ResourcesFolderName)

does not exist then

f = SpecialFolder.Desktop.Child(ResourcesFolderName).Child(PreferencesFolderName)

will be nil and

f = SpecialFolder.Desktop.Child(ResourcesFolderName).Child(PreferencesFolderName).Child(PreferencesFileName)

will raise an exception

step through this version of your code and you’ll see

Dim f As folderitem
f = SpecialFolder.Desktop.Child("ResourcesFolderName") // doesn't exist
f = SpecialFolder.Desktop.Child("ResourcesFolderName").Child("PreferencesFolderName") // f is now NIL
f = SpecialFolder.Desktop.Child("ResourcesFolderName").Child("PreferencesFolderName").Child("PreferencesFileName") //boom !

@Norman Palardy : Hello Norman. Does that mean I have to go through each one? or is there an easier way?



I’d go through each one
That way if you find that one doesn’t exist but SHOULD you have the chance to create it
If you dont you have a harder time knowing WHAT is wrong - like your initial post

If you are on Windows, check that the path is not > 255 or 256 characters ( whichever the limit is, can’t remember ).

Me, I check each one at a time, for nil and existence, else crocodiles eat you for lunch.

Good point Norman.