18 #include <boost/filesystem.hpp>
32 auto npos = name.find_first_of(
'.');
33 return npos != std::string::npos ? name.substr(npos, name.size() - npos) : std::string();
41 boost::filesystem::path path(dir_name);
43 return boost::filesystem::create_directory(dir_name);
51 boost::filesystem::path path(dir_name);
53 return boost::filesystem::create_directories(path);
58 std::vector<std::string> ret;
59 if (!boost::filesystem::exists(dir_name))
60 throw std::runtime_error(
"FileSystemUtils::filesInDirectory '" + dir_name
61 +
"' does not exist");
62 boost::filesystem::directory_iterator end_it;
63 for (boost::filesystem::directory_iterator it(dir_name);
64 it != boost::filesystem::directory_iterator(); ++it) {
65 if (!boost::filesystem::is_regular_file(it->status()))
67 ret.push_back(it->path().filename().string());
76 boost::filesystem::path path1(spath1);
77 boost::filesystem::path path2(spath2);
78 boost::filesystem::path full_path = path1 / path2;
80 return full_path.string();
85 return boost::filesystem::path(path).filename().string();
90 std::vector<std::string> ret;
92 if (std::regex_match(fname, std::regex(pattern)))
99 return boost::filesystem::path(path).stem().string();
105 auto npos = name.find_first_of(
'.');
106 return npos != std::string::npos ? name.substr(0, npos) : std::string();
111 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
112 return converter.from_bytes(str);
120 boost::filesystem::path path(str);
122 return boost::filesystem::exists(path);
Defines the macro ASSERT.
#define ASSERT(condition)
Defines many exception classes in namespace Exceptionss.
Defines namespace FileSystemUtils.
std::string extensions(const std::string &path)
Returns extension(s) of given 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::string stem_ext(const std::string &path)
Returns filename without extension(s).
std::string extension(const std::string &path)
Returns extension of given filename.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
std::vector< std::string > glob(const std::string &dir, const std::string &pattern)
Returns file names that agree with a regex glob pattern.
bool IsFileExists(const std::string &str)
Returns true if file with given name exists on disk.
std::string stem(const std::string &path)
Returns filename without extension.
std::vector< std::string > filesInDirectory(const std::string &dir_name)
Returns filenames of files in directory.
std::string jointPath(const std::string &spath1, const std::string &spath2)
Returns joint path name.
bool createDirectories(const std::string &dir_name)
Creates directories in current directory for any element of dir_name which doesn't exist.
bool createDirectory(const std::string &dir_name)
Creates directory in current directory.