//-------------------------------------------------------------- string ofApp::getFirstFile( ofDirectory& directory, const string ext){ if (!directory.exists()) { return ""; } directory.open( directory.path() ); directory.allowExt(ext); directory.listDir(); unsigned int i = directory.size(); string firstFile = ""; bool got = false; while (i--) { string currentFile = directory.getName(i); if ( !got || (currentFile.compare(firstFile) < 0) ){ firstFile = currentFile; got = true; } } return firstFile; }
//-------------------------------------------------------------- bool ofApp::deletePrevious( ofDirectory& directory, string filename) { if (!directory.exists()) { return 0; } directory.open( directory.path() ); directory.allowExt( ofFilePath::getFileExt(filename) ); directory.listDir(); unsigned int i = directory.size(); string* toDelete = new string [i]; unsigned int n = 0; while (i--) { string currentFile = directory.getName(i); if ( currentFile.compare(filename) < 0 ){ toDelete[n] = currentFile; n++; } } while (n--) { ofFile::removeFile( directory.path() + "/" + toDelete[n] ); } delete [] toDelete; directory.open( directory.path() ); return 1; }