List files in Documents directory

Hello,

I’m struggling with accessing the Documents folder contents on iOS using OF 0.8.4. I’ve looked through the forum and eventually ended up with something like this:

    int filesCount = dir.listDir(ofxiPhoneGetDocumentsDirectory());
    for(int i = 0; i < filesCount; i++){
        cout << dir.getPath(i);
    }

The above is as simple as it can be but it causes a EXC_BAD_ACCESS in ofFileUtils.cpp in void ofDirectory::open(string path) the originalDirectory = path; line. To be that it’s not a problem caused by empty dir I’ve added one file via iTunes.
I’ve also tried calling ofDisableDataPath(); but this yields the same results. The stack trace looks like this:

I’ve also tried changing the path referencing by:

    string dirPath(ofxiPhoneGetDocumentsDirectory());
    int filesCount = dir.listDir(dirPath);

But with the same result.

Did someone have an issue similar to this and maybe knows how to solve that?
The string returned by ofxiPhoneGetDocumentsDirectory() seems fine as it’s “/var/mobile/Containers/Data/Application/EB1489D8-537F-4EFB-B363-204AC42024FC/Documents/” which I think is ok.

Best regards

Hello @mog,

can you try this?

    ofDirectory dir;
    string folderPath = ofxiPhoneGetDocumentsDirectory();
    dir.open(folderPath);
    int numFiles = dir.listDir();
    
    for (int i=0; i<numFiles; ++i)
    {
        cout << "Path at index [" << i << "] = " << dir.getPath(i) << endl;
    }

Best,
V

1 Like

Thanks @Vjacobs ! I’ve missed the int ofDirectory::listDir() which works great.

    dir.open(ofxiPhoneGetDocumentsDirectory());
    int numFiles = dir.listDir();