Skip to content

Instantly share code, notes, and snippets.

@aman-tiwari
Created February 19, 2016 23:20
Show Gist options
  • Save aman-tiwari/daa815b4c6e938875017 to your computer and use it in GitHub Desktop.
Save aman-tiwari/daa815b4c6e938875017 to your computer and use it in GitHub Desktop.
Recursive directory search in openframeworks
const string allowed_ext[] = {"jpg", "png", "gif", "jpeg"}; //File types detected by the search
vector<ofFile> files;
void ofApp::scan_dir(ofDirectory dir){
ofDirectory new_dir;
int size = dir.listDir();
for (int i = 0; i < size; i++){
if (dir.getFile(i).isDirectory()){
new_dir = ofDirectory(dir.getFile(i).getAbsolutePath());
new_dir.listDir();
new_dir.sort();
scan_dir(new_dir);
} else if (std::find(std::begin(allowed_ext),
std::end(allowed_ext),
dir.getFile(i).getExtension()) != std::end(allowed_ext)) {
files.push_back(dir.getFile(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment