'Sample Files' .. copy files from resources to documents at runtime

In MAC OS, I bundle a zip file holding some files in the resources folder, and unpack the files into Documents on first run

I want to do the same in iOS, so that the user has the option to delete the sample files if they wish.
There is no simple unzip.
Im using Xojo 2017
To access the files in Resources, I need to know what they are called.
That means that to copy 200 files from my app to documents, I need 200 lines of code, rather than a nice simple loop.

Is there any way to move files bundled with the app into documents in a loop?

http://developer.xojo.com/xojo-io-folderitem

It’s all in the documentation. Make a subfolder in your resources and copy it’s children

Its doing a good job of hiding.

SampleFiles is a folder with things in it

dim res as FolderItem res = SpecialFolder.GetResource(Samplefiles) // fails .. this item does not exist

I cant find a way to reference the Resources folder, or a folder within it.
If I could, I could use CopyTo

Untested but should be something like:

Using Xojo.io Dim res as folderitem = specialfolder.resources() Dim doc as folderitem = specialfolder.documents() Dim sample as folderitem = res.child(“mycoolsample”) For each f as folderitem in sample.children() F.copyto(doc.child(f.name)) Next

Edit: fixed formatting

I know.
But specialfolder.resources() doesnt exist in Xojo 2017,
and although its mentioned in the docs for MacOS and Windows, it isnt documented for iOS in 2018R2 either.
Instead, getresource() is a function, which means you must know the name of the things before you use them

Specialfolder.resources exists in 2018r2. http://developer.xojo.com/2018r2-release-notes

For iOS you really want to be using the latest version or your app won’t be accepted into the App store

As I said, the notes don’t mention iOS at all.
Only how that feature functions on MacOS and WIndows.
I did read them before I posted this post.

So this hasn’t been possible for as long as Xojo has had the ability to build for iOS?

Create copy files build step and place all files in a subdirectory of Ressources.

You can then use getresource(subfoldername)

Only with the small workaround to use getresource on a known item in the resources folder and then address its parent.

Interesting!

I’ll get back to this in about 12 hours.Thanks for the hints

I believe you can pass an empty text literal to GetResource as well.

Thanks all for the help.
For anyone else, my full steps were:

Add a CopyFiles step to the project
Drag in some files
In the inspector, give it a Subdirectory folder name (Samples), and a target of Resources

In App.Open event:

dim fldsampl as folderitem dim sm as folderitem //target folder dim editsamples as folderitem = SpecialFolder.documents.child("Samples") if not editsamples.exists then //source folder fldsampl = SpecialFolder.GetResource("Samples") //create target if it hasn't been done (first pass) editsamples.CreateAsFolder //loop through children - probably could use copyto but this give a bit more control for later for each sm in fldsampl.Children sm.CopyTo editsamples.child(sm.DisplayName) next end if

Why?
The list of sample files might be large.
Users can choose to delete the sample files or their own documents.
If the samples were in specialfolder.resources, they are essentially read-only and not deletable

I don’t really understand the need to copy the sample files. Basically you are using twice as much storage space as the files are both in the app bundle and in documents.

It would make more sense to give the user the option to download the files if needed.

That was my argument against this method on Mac files years ago.
I gave up arguing against the people who say ‘space is cheap, so let someone else worry about it’
I’ve been shipping samples (zipped) in my Mac apps for a long long time.

But no, I don’t want people to have to install the app and then have to wait for a download of other stuff.
Samples should be there from first use.
EXTRA samples … that’s a different question.