@@ -28,8 +28,13 @@ void FileManager::info() {
2828 __print_all ();
2929}
3030
31- FileManager::file_info
32- FileManager::make_file_info (std::string filename, std::string relative_filename,
31+ bool FileManager::exists (const std::string &path) { return __check_path_if_exists (path); }
32+
33+ bool FileManager::__check_path_if_exists (const std::string &path) {
34+ return opendir (path.c_str ()) != nullptr ;
35+ }
36+
37+ FileManager::file_info FileManager::make_file_info (std::string filename, std::string relative_filename,
3338 bool is_dir) {
3439 // f.name is the absolute name
3540 // f.rname is name of the folder/file
@@ -47,7 +52,6 @@ FileManager::list_files(std::vector<std::string> extensions,
4752 // This returns the list of files present in the folder: corePath
4853 // TODO: Add tests, check if corePath is not empty
4954 // Converting #ifdef DEBUG and #endif to a macro
50-
5155 std::vector<file_info> list_files;
5256 std::string base_name;
5357
@@ -61,7 +65,8 @@ FileManager::list_files(std::vector<std::string> extensions,
6165 DIR *dir;
6266 struct dirent *ent;
6367 bool is_dir;
64- if ((dir = opendir (base_name.c_str ())) != NULL ) {
68+ if (exists (base_name)) {
69+ dir = opendir (base_name.c_str ());
6570 while ((ent = readdir (dir)) != NULL ) {
6671 bool include = false ;
6772 std::string relative_filename = ent->d_name ;
@@ -211,10 +216,8 @@ void FileManager::writeToFile(std::vector<std::string> ignore_dirs,
211216 file.close ();
212217}
213218
214- void FileManager::set_separator (const std::string& new_separator) {
219+ void FileManager::set_separator (const std::string & new_separator) {
215220 this ->separator = new_separator;
216221}
217222
218- std::string FileManager::get_separator () {
219- return this ->separator ;
220- }
223+ std::string FileManager::get_separator () { return this ->separator ; }
0 commit comments