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?
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
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
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.