diff --git a/stim/parser/filename.h b/stim/parser/filename.h index ee837dc..62ba09f 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -110,7 +110,7 @@ public: } - + /// Outputs the file name (including prefix and extension) std::string get_name(){ if(prefix == "" && ext == "") return ""; @@ -118,14 +118,18 @@ public: return prefix + "." + ext; } + /// Output the file extension only (usually three characters after a '.') std::string get_extension(){ return ext; } + /// Output the file prefix only (name before the extension) std::string get_prefix(){ return prefix; } + /// Output the entire path (not including the filename) + /// ex. "c:\this\is\the\directory\" std::string dir(){ std::stringstream ss; @@ -146,17 +150,17 @@ public: } + /// Output the entire string, including the path and filename + /// ex. "c:\this\is\a\directory\file.txt" std::string str(){ - - std::stringstream ss; - - ss< get_list(){ -#ifdef _WIN32 - //get a list of files matching the current template - + //this is OS dependent, so we're starting with Windows + //the Unix version requires Boost - //stim::filename file_path; - stim::filename filepath(dir_fname()); +#elif _WIN32 + stim::filename filepath(dir_fname()); //initialize filepath with the mask - HANDLE hFind = INVALID_HANDLE_VALUE; + HANDLE hFind = INVALID_HANDLE_VALUE; //allocate data structures for looping through files WIN32_FIND_DATAA FindFileData; - std::vector file_list; + std::vector file_list; //initialize a list to hold all matching filenames - hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); + hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); //find the first file that matches the specified file path - if (hFind == INVALID_HANDLE_VALUE) { - printf ("Invalid file handle. Error is %u.\n", GetLastError()); + if (hFind == INVALID_HANDLE_VALUE) { //if there are no matching files + printf ("Invalid file handle. Error is %u.\n", GetLastError()); //print an error } else { - std::string file_name = FindFileData.cFileName; //get the file name - std::string file_path = dir(); - stim::filename current_file(file_path + file_name); - file_list.push_back(current_file); + std::string file_name = FindFileData.cFileName; //save the file name + std::string file_path = dir(); //the file is in the specified directory, so save it + stim::filename current_file(file_path + file_name); //create a stim::filename structure representing this file + file_list.push_back(current_file); //push the new stim::filename to the file list // List all the other files in the directory. - while (FindNextFileA(hFind, &FindFileData) != 0){ - file_name = FindFileData.cFileName; - current_file = (f_name(file_name)); - file_list.push_back(current_file); + while (FindNextFileA(hFind, &FindFileData) != 0){ //iterate until there are no more matching files + file_name = FindFileData.cFileName; //save the next file + current_file = (f_name(file_name)); //append the directory + file_list.push_back(current_file); //push it to the list } - FindClose(hFind); + FindClose(hFind); //close the file data structure } - return file_list; + return file_list; //return the list of files #elif BOOST_PRECOMPILED -- libgit2 0.21.4