Inconsistent file load

Hi All,

I thought I had this all sorted out, but for some reason the loading of the files in my resource folder is not being very consistent.

Here is the code:

Var file01 As New FolderItem
Var file02 As New FolderItem
Var file03 As New FolderItem

file01 = SpecialFolder.Resource("template01.txt")
file02 = SpecialFolder.Resource("template02.txt")
file03 = SpecialFolder.Resource("template03.txt")

The name of the folder in my CopyFiles build step is: Resources

When I watch the method in the debugger 9 times out of 10 the variables “file0X” all show Nil.
One time file01 showed the file loaded, but not since which is crazy to me. Either it should be loading or it should not.

Can anyone tell me where I am going awry?

Thanks.

Do you want to use .Resource or .Resources?

Resource(name As String) As FolderItem
Returns a FolderItem to the specified file in the app’s SpecialFolder folder.
The provided name should be a file name, not a file path.

Resources
Windows: MyApp Folder\Resources
Mac: MyApp.app/Contents/Resources
Linux: MyApp Folder/Resources

@Tim_Hare pointed out to me the other day that those are two very different things.

The “Specialfolder.Resource”, from the docs, Returns a FolderItem to the specified file in the app’s SpecialFolder folder.

If I try to use the plural I cannot pass it a file name because it complains that I am trying to use it as an array.

Correct, if you copy your files to the Resources folder, you can’t access them because Resource is not looking at the Resources folder (from what I understand).

I know I can’t edit them or change them, but I thought that was a place to put read-only objects. In my case, template files.

Where should I be putting them then if not there?

No but you can use:

Var file01 As New FolderItem
Var file02 As New FolderItem
Var file03 As New FolderItem

file01 = SpecialFolder.Resources.Child("template01.txt")
file02 = SpecialFolder.Resources.Child("template02.txt")
file03 = SpecialFolder.Resources.Child("template03.txt")
2 Likes

You put them in the Resources, and use them with:

Specialfolder.Resources.Child(<your file>)


Ian was faster.

1 Like

We usually let Xojo handle the place for us as:

But if you build it, the folder has another name and works anyway:

Hi @Rick_Araujo ,

When I put the template files into the CopyFile step individually, like your screen capture shows, it copies the files into the root of the application with the exe.
If I copy the folder I created called Resources in the same directory as my project file it creates the folder in the debug build as “Resources” without any modification to the folder name.
Is there a setting I need to change to alter that behavior or is it something else I am missing?

Thanks!

Hi @AlbertoD and @Ian_Kennedy ,

When I try that it gives me a NilObjectException.

Where am i going astray there?

Reading your previous post, it looks like the copy step is not putting the files in the Resources folder.

1 Like

Make sure your copy step runs for both Debug and Build. Ensure that it is still set to copy the files to resources and that your source path is correct.

Agreed, they only end up there ifi explicitly copy the folder I created called Resources

It will produce an NilObjectException if the Resources folder doesn’t exist. That would likely only be the case if there are no images, icons etc within your application.

No copy just the file and set the Destination to Resources. Xojo will make the folder for you.

Copying a folder called Resources could lead to problems for other items that should go in there, such as icon files, images etc.

Obviously the copy files step needs to go after the Build step and before the Sign step (if you are on a Mac, or Windows does signing).

1 Like

You must be setting something wrong, like App Parent Folder instead of Resources

1 Like

@Rick_Araujo and @Ian_Kennedy ~ Yep! That was what I was missing!
I will change that and try again.
I will follow up here if that fails for me.

1 Like