NilObjectException on files/folders under AppData

I need to open a file that resides in the AppData\Local folder. Since there’s not a SpecialFolder property for this folder (most are for AppData\Roaming), I tried starting with SpecialFolder.UserHome and drilling down from there. I keep getting a NilObjectException when referencing anything in or below the Local folder (e.g. C:\Users\username\AppData\Local\somefile). Yet, I can use GetFolderItem with a hardcoded path with or without Child items and it all works fine. In all these cases, the file and/or folder does indeed exist. Here’s some examples:

[code]Dim f As FolderItem
// the following causes a NilObjectException
f = SpecialFolder.UserHome.Child(“AppData”).Child(“Local”).Child(“Star”).Child(“star.ini”) '<= NilObjectException

// and so does this
f = SpecialFolder.UserHome.Child(“AppData”).Child(“Local”).Child(“somefile”) '<= NilObjectException

// this works fine
f = SpecialFolder.UserHome.Child(“AppData”).Child(“Local”)
// but if you then try to build from there, it doesn’t:
f = f.Child(“somefile”) '<= NilObjectException

// these are the only ways I can get it to work
f = GetFolderItem(“C:\Users\Jay\AppData\Local\Star\Star.ini”, FolderItem.PathTypeAbsolute)
// or
f = GetFolderItem(“C:\Users\Jay”, FolderItem.PathTypeAbsolute)
f = f.Child(“AppData”).Child(“Local”).Child(“Star”).Child(“star.ini”)
[/code]

What’s also confusing is that the docs for Child state that if the file or folder doesn’t exist, then f will be nil. But it doesn’t get far enough to test that - it crashes with a NilObjectException.

To get directly to AppData, I do

Dim f as folderitem = SpecialFolder.ApplicationData.Parent

SpecialFolder.ApplicationData points to Roaming indeed, so adding .Parent points to AppData.

No need to build from the user home.

This works perfectly :

Dim f as folderitem = SpecialFolder.ApplicationData.Parent.child("local").child("Star").child("star.ini") f.launch

can you use SpecialFolder.ApplicationData.Child(“Local”).Child(“Star”).Child(“star.ini”) ?

see SpecialFolder

this shows the path

Dim f As FolderItem f = SpecialFolder.ApplicationData If f <> Nil Then MsgBox(f.AbsolutePath) Else MsgBox("There is no Application Data folder on this computer.") End If

[quote=204955:@Michel Bujardet]To get directly to AppData, I do

Dim f as folderitem = SpecialFolder.ApplicationData.Parent

This works perfectly :

Dim f as folderitem = SpecialFolder.ApplicationData.Parent.child("local").child("Star").child("star.ini") f.launch[/quote]

Yes, it does. So why doesn’t my method? Isn’t this really a bug?

I don’t know. I just tried, and it works just fine.