-
-
Save loginsmruti/f6662d98a2b8e17367031b89af1f2df7 to your computer and use it in GitHub Desktop.
Revisions
-
deysumitkr revised this gist
Sep 26, 2017 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,12 @@ std::vector<std::string> exts{".jpg", ".png"}; std::vector<std::string> files = getFilesInDir("/path/to/root/directory/", exts, true); // -------------------------------------------------------- #define BOOST_FILESYSTEM_NO_DEPRECATED #include <boost/filesystem.hpp> /** * @note If extension is empty string ("") then all files are returned * @param Path root directory @@ -49,4 +53,4 @@ std::vector<std::string> getFilesInDir(const std::string &path, const std::vecto outArray.insert(outArray.end(), files.begin(), files.end()); } return outArray; } -
deysumitkr revised this gist
Sep 26, 2017 . No changes.There are no files selected for viewing
-
deysumitkr renamed this gist
Sep 26, 2017 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,15 @@ // usage std::vector<std::string> exts{".jpg", ".png"}; std::vector<std::string> files = getFilesInDir("/path/to/root/directory/", exts, true); // -------------------------------------------------------- /** * @note If extension is empty string ("") then all files are returned * @param Path root directory * @param extension String or vector of strings to filter - empty string returns all files - default: "" * @param recursive Set true to scan directories recursively - default false * @return Vector of strings with full paths */ std::vector<std::string> getFilesInDir(const std::string &path, const std::string &extension="", const bool &recursive=false){ -
deysumitkr created this gist
Sep 26, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ /** * @note if extension is empty string ("") then all files are returned * @param path root directory * @param extension string or vector of strings to filter - empty string returns all files - default: "" * @param recursive set true to scan directories recursively - default false * @return vector of strings with full paths */ std::vector<std::string> getFilesInDir(const std::string &path, const std::string &extension="", const bool &recursive=false){ std::vector<std::string> files; boost::filesystem::path dir(path); if(boost::filesystem::exists(path) && boost::filesystem::is_directory(path)){ if(recursive){ boost::filesystem::recursive_directory_iterator it(path); boost::filesystem::recursive_directory_iterator endit; while (it != endit) { if(boost::filesystem::is_regular_file(*it) && (extension=="")?true:it->path().extension() == extension) { files.push_back(it->path().string()); } ++it; } } else { boost::filesystem::directory_iterator it(path); boost::filesystem::directory_iterator endit; while (it != endit) { if(boost::filesystem::is_regular_file(*it) && (extension=="")?true:it->path().extension() == extension) { files.push_back(it->path().string()); } ++it; } } } return files; } std::vector<std::string> getFilesInDir(const std::string &path, const std::vector<std::string> &extension, const bool &recursive=false){ if(extension.size() <=0) return getFilesInDir(path, "", recursive); std::vector<std::string> outArray; for (const std::string &ext: extension){ std::vector<std::string> files = getFilesInDir(path, ext, recursive); outArray.insert(outArray.end(), files.begin(), files.end()); } return outArray; }