Skip to content

Commit

Permalink
init: Load file.json, not file.json.bak, file.json.orig, .tmp.file.js…
Browse files Browse the repository at this point in the history
…on.swp, etc
  • Loading branch information
atomicdryad committed Nov 24, 2013
1 parent 1a8f627 commit e17ce6c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/file_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
if true, continue searching all child directories from the supplied root_path
if false, search only the supplied root_path, and stop when the directory contents have been worked through.
*/
std::vector<std::string> file_finder::get_files_from_path(std::string extension, std::string root_path, bool recursive_search)
std::vector<std::string> file_finder::get_files_from_path(std::string extension, std::string root_path, bool recursive_search, bool match_extension)
{
std::vector<std::string> files;

const size_t extsz = extension.size();
const char * c_extension = extension.c_str();
// test for empty root path
if (root_path.empty())
{
Expand Down Expand Up @@ -77,9 +78,8 @@ std::vector<std::string> file_finder::get_files_from_path(std::string extension,
}
// check to see if it is a file with the appropriate extension
std::string tmp = root_file->d_name;
if (tmp.find(extension.c_str()) != std::string::npos)
if ( tmp.find(c_extension, match_extension ? tmp.size()-extsz : 0 ) != std::string::npos )
{
// file with extension found! add to files list with full path
std::string fullpath = path + "/" + tmp;
files.push_back(fullpath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/file_finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class file_finder
{
public:
static std::vector<std::string> get_files_from_path(std::string extension, std::string root_path = "", bool recursive_search = false);
static std::vector<std::string> get_files_from_path(std::string extension, std::string root_path = "", bool recursive_search = false, bool match_extension = false);
static std::vector<std::string> get_directories_with(std::vector<std::string> extensions, std::string root_path = "", bool recursive_search = false);
protected:
private:
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void load_json_dir(std::string const &dirname)
{
// get a list of all files in the directory
std::vector<std::string> dir =
file_finder::get_files_from_path(".json", dirname, true);
file_finder::get_files_from_path(".json", dirname, true, true);
// iterate over each file
std::vector<std::string>::iterator it;
for (it = dir.begin(); it != dir.end(); it++) {
Expand Down

0 comments on commit e17ce6c

Please sign in to comment.