void OGUIFileBrowser::readFolder(string path) { realpath(path.c_str(), resolved_path); _file_list.clear(); tinydir_dir dir; if (tinydir_open_sorted(&dir, resolved_path) == -1) { cout << "Error opening file" << endl; return; } for (int i = 0; i < dir.n_files; i++) { tinydir_file file; if (tinydir_readfile_n(&dir, &file, i) == -1) { cout << "Error getting file" << endl; return; } if(strcmp(file.name,".")==0 || (file.name[0]=='.' && file.name[1]!='.')) continue; OGUIFile *oguifile= new OGUIFile(_window, file.name, file.path, file.is_dir, file.extension, 0); _file_list.push_back(oguifile); printf("\n"); } tinydir_close(&dir); }
/** * Get the list of midi files directly in the given directory * return a vector of file names * note: we don't check if they are valid MIDI files, only if the * MIDI extension is here */ static std::vector<std::string> get_midi_files(const std::string& path) { const std::string MIDI_EXTENSION(".mid"); std::vector<std::string> midiFileNames; tinydir_dir midiDir; tinydir_open_sorted(&midiDir, path.c_str()); for (unsigned i = 0; i < midiDir.n_files; i++) { tinydir_file file; tinydir_readfile_n(&midiDir, &file, i); if (file.is_dir) { continue; } std::string tmpFileName(file.name); std::cout << tmpFileName << std::endl; if (!ends_with(tmpFileName, MIDI_EXTENSION)) { continue ; } std::cout << tmpFileName << std::endl; midiFileNames.push_back(tmpFileName); } tinydir_close(&midiDir); return midiFileNames; }
std::list<std::string> getFilesInDirs(const std::list<std::string> & directory_list) { std::list<std::string> files; for (std::list<std::string>::const_iterator it = directory_list.begin(); it != directory_list.end(); ++it) { tinydir_dir dir; dir.has_next = 0; // Avoid a garbage value in has_next (clang StaticAnalysis) tinydir_open(&dir, it->c_str()); while (dir.has_next) { tinydir_file file; file.is_dir = 0; // Avoid a garbage value in is_dir (clang StaticAnalysis) tinydir_readfile(&dir, &file); if (!file.is_dir) files.push_back(*it + "/" + file.name); tinydir_next(&dir); } tinydir_close(&dir); } return files; }
void TinyDirInterface::close() { if (isOpen_) { path_ = std::string(); tinydir_close(&resource_); isOpen_ = false; } }
void MapParser::initCinematique(Cinematique* cinematique, CinematiqueView* cinematiqueView, const char* dossier) { tinydir_dir dir; tinydir_open(&dir, dossier); int nbImages = 0; while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if (!file.is_dir && file.name[0]!='T') { nbImages++; } tinydir_next(&dir); } tinydir_close(&dir); std::cout << "nb images cinematique " << dossier << " : " << nbImages << std::endl; cinematique->setNbImages(nbImages); cinematiqueView->m_cinematique = cinematique; for(int i=0; i<nbImages; i++) { std::stringstream s; s << dossier << "/" << i << ".png"; cinematiqueView->m_tex_images.push_back(sf::Texture()); cinematiqueView->m_tex_images.at(i).loadFromFile(s.str()); } }
vector< string > ScanFolder( const char* dir_path ) { vector< string > file_vec; tinydir_dir dir; //==== Open Path ====// if ( tinydir_open( &dir, dir_path ) == -1 ) { tinydir_close( &dir ); return file_vec; } //==== Load Files ====// while ( dir.has_next ) { tinydir_file file; if ( tinydir_readfile( &dir, &file ) == -1 ) { } else if ( file.is_dir ) { } else { file_vec.push_back( file.name ); } tinydir_next( &dir ); } return file_vec; }
mrb_value mrb_dir_entries(mrb_state* mrb, mrb_value self) { mrb_value entries = mrb_ary_new(mrb); mrb_value dirname; mrb_get_args(mrb, "S", &dirname); const char* name = mrb_string_value_ptr(mrb, dirname); tinydir_dir dir; if (tinydir_open(&dir, name) == -1) { mrb_raisef(mrb, E_RUNTIME_ERROR, "Error opening file: %S", mrb_str_new_cstr(mrb, name)); } while (dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); mrb_ary_push(mrb, entries, mrb_str_new_cstr(mrb, file.name)); tinydir_next(&dir); } tinydir_close(&dir); return entries; }
int ScanFolder() { tinydir_dir dir; if ( tinydir_open( &dir, "." ) == -1 ) { perror( "Error opening file" ); goto bail; } while ( dir.has_next ) { tinydir_file file; if ( tinydir_readfile( &dir, &file ) == -1 ) { perror( "Error getting file" ); goto bail; } printf( "%s", file.name ); if ( file.is_dir ) { printf( "/" ); } printf( "\n" ); tinydir_next( &dir ); } bail: tinydir_close( &dir ); return 0; }
void FileSystem::ReadFolder(const std::string& dir) { tinydir_dir d; tinydir_open(&d, dir.c_str()); while (d.has_next) { tinydir_file file; tinydir_readfile(&d, &file); if (file.is_dir && strcmp(file.name, ".") && strcmp(file.name, "..")) { ReadFolder(file.path); } else { if (strcmp(file.name, ".") && strcmp(file.name, "..")) { (*this)[file.name] = file.path; } } tinydir_next(&d); } tinydir_close(&d); }
int main(void) { tinydir_dir dir; if (tinydir_open_sorted(&dir, ".") == -1) { perror("Error opening file"); goto bail; } for (;;) { int i; char input[256]; for (i = 0; i < dir.n_files; i++) { tinydir_file file; if (tinydir_readfile_n(&dir, &file, i) == -1) { perror("Error getting file"); goto bail; } if (file.is_dir) { printf("[%d] ", i); } printf("%s", file.name); if (file.is_dir) { printf("/"); } printf("\n"); } printf("?"); if (fgets(input, 256, stdin) == NULL) { break; } else { int choice = atoi(input); if (choice >= 0 && choice < dir.n_files) { if (tinydir_open_subdir_n(&dir, choice) == -1) { perror("Error opening subdirectory"); goto bail; } } } } bail: tinydir_close(&dir); return 0; }
// // 1. Iterates through the chisel files on disk (.sc and .lua) // 2. Opens them and extracts the fields (name, description, etc) // 3. Adds them to the chisel_descs vector. // void sinsp_chisel::get_chisel_list(vector<chisel_desc>* chisel_descs) { for(vector<chiseldir_info>::const_iterator it = g_chisel_dirs->begin(); it != g_chisel_dirs->end(); ++it) { if(string(it->m_dir).empty()) { continue; } tinydir_dir dir; tinydir_open(&dir, it->m_dir); while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); string fpath(file.path); bool add_to_vector = false; chisel_desc cd; filename fn = split_filename(string(file.name)); if(fn.ext != "sc" && fn.ext != "lua") { goto next_file; } for(vector<chisel_desc>::const_iterator it_desc = chisel_descs->begin(); it_desc != chisel_descs->end(); ++it_desc) { if(fn.name == it_desc->m_name) { goto next_file; } } cd.m_name = fn.name; #ifdef HAS_LUA_CHISELS if(fn.ext == "lua") { add_to_vector = init_lua_chisel(cd, fpath); } if(add_to_vector) { chisel_descs->push_back(cd); } #endif next_file: tinydir_next(&dir); } tinydir_close(&dir); } }
void ImageFunction::getFiles() { #ifdef LIBMESH_HAVE_VTK // Storage for the file names _files = vtkSmartPointer<vtkStringArray>::New(); // Use specified file name if (isParamValid("file")) { std::string filename = getParam<FileName>("file"); _files->InsertNextValue(filename); _file_type = filename.substr(filename.find_last_of(".") + 1); } // File stack else { // Separate the file base from the path std::pair<std::string, std::string> split_file = MooseUtils::splitFileName(_file_base); // Create directory object tinydir_dir dir; tinydir_open_sorted(&dir, split_file.first.c_str()); // Regex for extracting numbers from file std::ostringstream oss; oss << "(" << split_file.second << ".*?(\\d+))\\..*"; pcrecpp::RE re_base_and_file_num(oss.str()); // Will pull out the full base and the file number simultaneously // Loop through the files in the directory for (unsigned int i = 0; i < dir.n_files; i++) { // Upate the current file tinydir_file file; tinydir_readfile_n(&dir, &file, i); // Store the file if it has proper extension as in numeric range if (!file.is_dir && MooseUtils::hasExtension(file.name, _file_type)) { std::string the_base; int file_num = 0; re_base_and_file_num.FullMatch(file.name, &the_base, &file_num); if (!the_base.empty() && file_num >= _file_range[0] && file_num <= _file_range[1]) _files->InsertNextValue(split_file.first + "/" + file.name); } } tinydir_close(&dir); } // Error if no files where located if (_files->GetNumberOfValues() == 0) mooseError("No image file(s) located"); #endif }
static void LoadArchivePics( PicManager *pm, const char *archive, const char *dirname) { char *buf = NULL; char path[CDOGS_PATH_MAX]; sprintf(path, "%s/%s", archive, dirname); tinydir_dir dir; if (tinydir_open(&dir, path) != 0) { LOG(LM_MAP, LL_DEBUG, "no pic dir(%s): %s", path, strerror(errno)); goto bail; } while (dir.has_next) { tinydir_file file; if (tinydir_readfile(&dir, &file) != 0) { LOG(LM_MAP, LL_WARN, "cannot read file: %s", strerror(errno)); break; } if (!file.is_reg) goto nextFile; long len; buf = ReadFileIntoBuf(file.path, "rb", &len); if (buf == NULL) goto nextFile; SDL_RWops *rwops = SDL_RWFromMem(buf, len); bool isPng = IMG_isPNG(rwops); if (isPng) { SDL_Surface *data = IMG_Load_RW(rwops, 0); if (data != NULL) { char nameBuf[CDOGS_FILENAME_MAX]; PathGetBasenameWithoutExtension(nameBuf, file.path); PicManagerAdd(&pm->customPics, &pm->customSprites, nameBuf, data); } } rwops->close(rwops); nextFile: CFREE(buf); buf = NULL; if (tinydir_next(&dir) != 0) { printf( "Could not go to next file in dir %s: %s\n", path, strerror(errno)); goto bail; } } bail: CFREE(buf); tinydir_close(&dir); }
static void LoadArchiveSounds( SoundDevice *device, const char *archive, const char *dirname) { char *buf = NULL; char path[CDOGS_PATH_MAX]; sprintf(path, "%s/%s", archive, dirname); tinydir_dir dir; if (tinydir_open(&dir, path) != 0) { LOG(LM_MAP, LL_DEBUG, "no sound dir(%s): %s", path, strerror(errno)); goto bail; } while (dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if (!file.is_reg) goto nextFile; long len; buf = ReadFileIntoBuf(file.path, "rb", &len); if (buf == NULL) goto nextFile; SDL_RWops *rwops = SDL_RWFromMem(buf, len); Mix_Chunk *data = Mix_LoadWAV_RW(rwops, 0); if (data != NULL) { char nameBuf[CDOGS_FILENAME_MAX]; strcpy(nameBuf, file.name); // Remove extension char *dot = strrchr(nameBuf, '.'); if (dot != NULL) { *dot = '\0'; } SoundAdd(&device->customSounds, nameBuf, data); } rwops->close(rwops); nextFile: CFREE(buf); buf = NULL; if (tinydir_next(&dir) != 0) { printf( "Could not go to next file in dir %s: %s\n", path, strerror(errno)); goto bail; } } bail: CFREE(buf); tinydir_close(&dir); }
std::vector<std::string> findFilesInDir(const std::string &directory, const std::vector<std::string> &extensions, bool stripExtension, bool recursive) { std::vector<std::string> files; std::stack<std::string> dirsLeft; dirsLeft.push(directory); tinydir_dir dir; while (!dirsLeft.empty()) { std::string dirPath = dirsLeft.top(); dirsLeft.pop(); // Try to open directory if (tinydir_open_sorted(&dir, dirPath.c_str()) != 0) continue; for (unsigned i = 0; i < dir.n_files; i++) { tinydir_file file; if (tinydir_readfile_n(&dir, &file, i) != 0) { continue; } if (file.is_dir) { if (recursive && file.name != std::string(".") && file.name != std::string("..")) { dirsLeft.push(file.path); } continue; } std::vector<std::string>::const_iterator eiter = std::find(extensions.begin(), extensions.end(), file.extension); if (eiter == extensions.end()) { continue; } std::string path(file.path); if (stripExtension) { size_t lastindex = path.find_last_of("."); std::string raw = path.substr(0, lastindex); files.push_back(raw); } else { files.push_back(path); } } tinydir_close(&dir); } return files; }
void Renderer::setupEmptyDirectory(const filesystem::path &path) { FileUtils::createDir(path.str()); tinydir_dir dir; tinydir_open_sorted(&dir, path.str().c_str()); for (size_t i = 0; i < dir.n_files; ++i) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); if (file.is_reg) { FileUtils::deleteFile((path / file.name).str()); } } tinydir_close(&dir); }
void MapParser::initZonesFromFiles() { std::string racineZones("./zones"); std::cout << "ouverture dossier zones" << std::endl; tinydir_dir dir; tinydir_open(&dir, racineZones.c_str()); while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if (file.is_dir && file.name[0]!='.') { std::string chemin = racineZones + "/" + file.name; std::cout << chemin << std::endl; parseAndInit(chemin, TAILLE_CASE_X, TAILLE_CASE_Y); } tinydir_next(&dir); } tinydir_close(&dir); //vérification debug: std::cout << "## portails trouvés : ##" << std::endl; std::map<sf::Uint32, std::pair<Destination, Destination> >::iterator it; for(it=m_portails.begin(); it!=m_portails.end(); it++) { std::cout << " " << it->first << "=>[ (zone:" << it->second.first.m_numZone << " \tx:" << it->second.first.m_x << " \ty:" << it->second.first.m_y << ") ~ (zone:" << it->second.second.m_numZone << " \tx:" << it->second.second.m_x << " \ty:" << it->second.second.m_y << ") ]\n"; } std::cout << "## (fin portails) ##" << std::endl; // CINEMATIQUES initCinematique(&Modeles::m_cinematiqueIntro, &Vues::m_cinematiqueViewIntro, "./intro"); initCinematique(&Modeles::m_cinematiqueFin, &Vues::m_cinematiqueViewFin, "./fin"); //TEXTURES OBJETS std::string texFichiers[] = { "sante.png", "arme.png", "bouton.png" }; std::string objRacine("./objets/"); for(int i=0; i<Objet::NB_OBJETS_ID; i++) { Objet::ObjetID id = (Objet::ObjetID) i; Vues::m_objetsView.addTexture(id, objRacine + texFichiers[i]); } }
void TryPrintAllFileNamesInFolder(std::string folder_dir_name, std::ostream &PRINT_HERE) { tinydir_dir dir; tinydir_open(&dir, folder_dir_name.c_str()); while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if(file.is_dir == false && file.name[0] != '.') { PRINT_HERE << "\"" << folder_dir_name << "\" contains:" << std::string(file.name) << std::endl; } tinydir_next(&dir); } tinydir_close(&dir); }
/** * @file main.c * @author Milán Unicsovics, u.milan at gmail dot com * @date August, 2013 * @brief Creates JSON array from *.mp3 files in current directory */ int main(void) { tinydir_dir dir; int i; int count = 0; if (tinydir_open_sorted(&dir, ".") == -1) { perror("Error opening file"); goto bail; } for (i = 0; i < dir.n_files; i++) { tinydir_file file; if (tinydir_readfile_n(&dir, &file, i) == -1) { perror("Error getting file"); goto bail; } size_t size = strlen(file.name); if (size >= 4 && file.name[size-4] == '.' && file.name[size-3] == 'm' && file.name[size-2] == 'p' && file.name[size-1] == '3') { count++; if (count == 1) { printf("["); } if (count > 1) { printf(","); } printf(" \"%s\"", file.name); } } if (count > 0) { printf("]"); } bail: tinydir_close(&dir); return 0; }
void PluginManager::LoadPlugins() { tinydir_dir dir; if (tinydir_open(&dir, PLUGINPATH) == -1) { Log("Error opening file"); } int cpt = 0; while (dir.has_next) { tinydir_file file; if (tinydir_readfile(&dir, &file) == -1) { Log("Error getting file"); } if (std::string(file.extension) == "dll") { void* handle = nullptr; handle = SDL_LoadObject(file.path); if (handle != nullptr) { std::vector<std::string>* (*func)(); func = (std::vector<std::string>*(*)())SDL_LoadFunction(handle, "GetPluginFeatures"); if (func != nullptr) { std::vector<std::string>* pluginFeatures = func(); _plugins.push_back(handle); for (std::string& str : (*pluginFeatures)) { _features[str].push_back(handle); } delete pluginFeatures; } else Log("Unable to load GetPluginFeatures function in : " + std::string(file.path)); } else Log("Unable to load plugin : "+std::string(file.path)); } tinydir_next(&dir); } tinydir_close(&dir); }
bool listFilesInDir(const std::string& rootDir, PathList* filesList, const std::string& extFilter, bool recursive) { bool success = true; if(!filesList) { errno = EINVAL; return false; } tinydir_dir dir; if(tinydir_open(&dir, rootDir.c_str()) == -1) return false; while(dir.has_next) { tinydir_file file; if(tinydir_readfile(&dir, &file) == -1) { success = false; continue; } // Regular file if(file.is_reg && (extFilter.empty() || extFilter == file.extension)) filesList->push_back(file.path); // Directory else if(recursive && file.is_dir && strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0) { if(!listFilesInDir(file.path, filesList, extFilter, true)) success = false; } if(tinydir_next(&dir) == -1) { success = false; break; } } tinydir_close(&dir); return success; }
mrb_value mrb_dir_exists(mrb_state* mrb, mrb_value self) { mrb_value dirname; mrb_get_args(mrb, "S", &dirname); const char* name = mrb_string_value_ptr(mrb, dirname); tinydir_dir dir; if (tinydir_open(&dir, name) == -1) { return mrb_false_value(); } tinydir_close(&dir); return mrb_true_value(); }
std::vector<std::string> GetImageFilenamesInFolder(std::string folder_dir_name) { std::vector<std::string> returnedFnames; tinydir_dir dir; tinydir_open(&dir, folder_dir_name.c_str()); while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if(file.is_dir == false && file.name[0] != '.' && filename_extension_is_image_type(get_extension_from_filename(file.name))) { returnedFnames.push_back(file.name); } tinydir_next(&dir); } tinydir_close(&dir); return returnedFnames; }
int CountNumImagesInFolder(std::string folder_dir_name) { int returned_num_images = 0; tinydir_dir dir; tinydir_open(&dir, folder_dir_name.c_str()); while(dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if(file.is_dir == false && file.name[0] != '.' && filename_extension_is_image_type(get_extension_from_filename(file.name))) { returned_num_images++; } tinydir_next(&dir); } tinydir_close(&dir); return returned_num_images; }
void LoadSongList(struct SongDef **songList, const char *dirPath) { tinydir_dir dir; int errsv; if (tinydir_open(&dir, dirPath) == -1) { errsv = errno; printf("Cannot open music dir: %s\n", strerror(errsv)); goto bail; } for (; dir.has_next; tinydir_next(&dir)) { Mix_Music *m; tinydir_file file; if (tinydir_readfile(&dir, &file) == -1) { errsv = errno; debug(D_VERBOSE, "cannot read file: %s\n", strerror(errsv)); goto bail; } if (!file.is_reg) { debug(D_VERBOSE, "not a regular file %s\n", file.name); continue; } if (strcmp(file.extension, "txt") == 0 || strcmp(file.extension, "TXT") == 0) { debug(D_VERBOSE, "Skipping text file %s\n", file.name); continue; } m = Mix_LoadMUS(file.path); if (m == NULL) { debug(D_VERBOSE, "not a music file %s\n", file.name); continue; } Mix_FreeMusic(m); AddSong(songList, file.path); } bail: tinydir_close(&dir); }
static void LoadCampaignsFromFolder( campaign_list_t *list, const char *name, const char *path, const GameMode mode) { tinydir_dir dir; int i; CSTRDUP(list->Name, name); if (tinydir_open_sorted(&dir, path) == -1) { printf("Cannot load campaigns from path %s\n", path); return; } for (i = 0; i < (int)dir.n_files; i++) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); // Ignore campaigns that start with a ~ // These are autosaved const bool isArchive = strcmp(file.extension, "cdogscpn") == 0 || strcmp(file.extension, "CDOGSCPN") == 0; if (file.is_dir && !isArchive && strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0) { campaign_list_t subFolder; CampaignListInit(&subFolder); LoadCampaignsFromFolder(&subFolder, file.name, file.path, mode); CArrayPushBack(&list->subFolders, &subFolder); } else if ((file.is_reg || isArchive) && file.name[0] != '~') { CampaignEntry entry; if (CampaignEntryTryLoad(&entry, file.path, mode)) { CArrayPushBack(&list->list, &entry); } } } tinydir_close(&dir); }
vector<string> LCSSaveFiles() { vector<string> save_files; tinydir_dir dir; tinydir_open(&dir, homedir); while (dir.has_next) { tinydir_file file; tinydir_readfile(&dir, &file); if(strstr(file.name, ".dat") != NULL &&strstr(file.name, "score") == NULL) save_files.push_back(file.name); tinydir_next(&dir); } tinydir_close(&dir); return save_files; }
std::list<std::string> dataHandler::filesIn(const char* folderName) { std::list<std::string> filesList; tinydir_dir dir; unsigned int i; tinydir_open_sorted(&dir, folderName); for (i = 0; i < dir.n_files; i++) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); if (!file.is_dir) { filesList.push_back(file.name); } } tinydir_close(&dir); return filesList; }
void dataHandler::tinydirExample() { tinydir_dir dir; unsigned int i; tinydir_open_sorted(&dir, "../data/test/bedroom"); for (i = 0; i < dir.n_files; i++) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); printf("%s", file.name); if (file.is_dir) { printf("/"); } printf("\n"); } tinydir_close(&dir); }
std::list<std::string> dataHandler::foldersIN(const char *folderName) { std::list<std::string> foldersList; tinydir_dir dir; unsigned int i; tinydir_open_sorted(&dir, folderName); // starts from 2 to get rid of ./ and ../ for (i = 2; i < dir.n_files; i++) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); if (file.is_dir) { foldersList.push_back(file.name); } } tinydir_close(&dir); return foldersList; }