24 namespace fs = std::filesystem;
28 return fs::path(path).extension().string();
42 const auto pos = name.find_first_of(
'.', 1);
43 return pos != std::string::npos ? name.substr(pos, name.size() - pos) :
"";
51 return fs::create_directory(dir_name);
60 return fs::create_directories(dir_name);
66 std::vector<std::string> result;
67 if (!fs::exists(dir_name))
68 throw std::runtime_error(
"BaseUtils::Filesystem::filesInDirectory '" + dir_name
69 +
"' does not exist");
71 for (
const auto& entry : fs::directory_iterator(dir_name))
72 if (entry.is_regular_file())
73 result.push_back(entry.path().filename().string());
83 return fs::path(path2).string();
85 return (fs::path(path1) / fs::path(path2)).string();
90 return fs::path(path).filename().string();
94 const std::string& pattern)
96 std::vector<std::string> result;
98 if (std::regex_match(fname, std::regex(pattern)))
99 result.push_back(fname);
105 return fs::path(path).stem().string();
114 const auto pos = name.find_first_of(
'.', 1);
115 return pos != std::string::npos ? name.substr(0, pos) : name;
120 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
121 return converter.from_bytes(str);
129 return fs::exists(path);
Defines the macro ASSERT.
#define ASSERT(condition)
Defines a few helper functions.
Defines namespace FileSystemUtils.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
std::string extensions(const std::string &path)
Returns extension(s) of given filename. "/home/user/filename.int" -> ".int", "/home/user/filename....
std::string jointPath(const std::string &path1, const std::string &path2)
Returns joint path name. Argument path1 may be empty, argument path2 not.
std::string stem_ext(const std::string &path)
Returns filename without extension(s). "/home/user/filename.int" -> "filename", "/home/user/filename....
bool createDirectory(const std::string &dir_name)
Creates directory in current directory.
std::string extension(const std::string &path)
Returns extension of given filename. "/home/user/filename.int" -> ".int", "/home/user/filename....
std::wstring convert_utf8_to_utf16(const std::string &str)
Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
std::vector< std::string > filesInDirectory(const std::string &dir_name)
Returns filenames of files in directory.
std::string stem(const std::string &path)
Returns filename without (last) extension. "/home/user/filename.int" -> "filename",...
bool createDirectories(const std::string &dir_name)
Creates directories in current directory for any element of dir_name which doesn't exist.
std::vector< std::string > glob(const std::string &dir, const std::string &pattern)
Returns file names that agree with a regex glob pattern.
bool hasExtension(const std::string &path, const std::string &ref_extension)
Returns true if extension of path, converted to lower case, matches given reference extension.
bool IsFileExists(const std::string &path)
Returns true if file with given name exists on disk.
std::string to_lower(std::string text)
Returns new string which is lower case of text.