ofDirectory - path is empty error

Can’t understand why this doesn’t work:
ofDirectory dir;


string path ="/Volumes/data/folder1;
    dir.createDirectory(path); // OK directory gets created
    cout << dir.path() <<endl; // nothing

also if I then put files in the directory dir.listDir(); just says it is empty:
[ error ] ofDirectory: listDir(): directory path is empty

However if I create a directory ‘on the fly’ it seems fine:
string path ="/Volumes/data/folder1";
ofDirectory dir(path);
dir.listDir(); // seems fine.

What am I missing here?


The first line of the code is missing " in the end. Don’t know if that is the reason though.

Thanks. True - but thats just my bad cut and paste(!)…( app wouldn’t even compile without the quote.)

Don’t seem to have a way to get a permanent ref. to a directory with ofDirectory.
‘dir’ is a property in ofApp.h and does not go out of scope anywhere or
get nulled/niled/erased or whatever so it seems strange its path should be empty in dir.path().

Funnily enough I know how to do it the ‘difficult’ way directly in C++ LOL

Variable “dir” is never initialized in your code. Try using open() and create():

string path ="/Volumes/data/folder1;
1 Like