Copying files problem


Hey All,

Not sure if this is specifically an iOS issue, but that's where I'm having problems. This is probably user error, but I can't figure out what I did wrong. 

My app has a bundle of factory presets (xml files) which I am trying to install into the app's documents folder. So it should just be a simple copy operation when first running the app, but I am getting tripped up. Here's what I'm doing. Any suggestions?

I am able to save to the documents directory just fine from my app, it's just in this scenario, nothing happens. Am I misusing copyFileTo?

Array<File> presetList;

File file = File::getSpecialLocation(File::currentApplicationFile).getChildFile("Presets.bundle");

file.findChildFiles (presetList, File::findFiles, false, "*.xml"); //fill presetList array with xml files

for (int i=0; i < presetList.size(); ++i)
    String filename = presetList[i].getFileName();
    log->writeToLog(filename); //just confirming that I actually have presets to copy! (i do)

    File fileToCopy = presetList[i];



humbly and wearily,



The copyFileTo method requires a target filename, not just the parent folder.


Thanks Jules. That's a good one for the documentation! Although I did try appending getNonexistentChildFile, but that didn't appear to work either  (also, I don't want the usual behavior of that function, which doesn't overwrite files but instead adds similarly named duplicates, I just want to overwrite those files if they exist already). Is there something else I'm missing? This is what I tried:

                           .getSiblingFile("Documents").getNonexistentChildFile ("preset", ".xml"));



I'd have thought that that folder would actually be read-only on OSX..


Maybe the root folder is that way, but the documents folder is meant to be written to. I am successfully doing it from elsewhere in my app. Is the copy function trying to create a copy where the source file is temporarily or something like that?

edit: also, just to be clear, I'm talking about iOS not OSX


Surely you should be using File::userDocumentsDirectory?

And rather than wondering about whether it makes a temporary file, you can just debug into the method and see exactly what it does and where it fails.


at one point userDocumentsDirectory did not point to the correct place on iOS for me, so that's a carryover from that I think. Maybe it does work now, I'll check.

I will try to debug a bit and see if I can understand what's going on.


Never mind. It was the goddamn simulator! Works fine on iPad. Maybe something broke in the last Xcode update with document saving in the simulator. Not sure, don't care, bigger problems to worry about :D. 

Word to the wise, test on a real device.