12 #include <boost/filesystem/operations.hpp> 16 namespace fs = boost::filesystem;
19 fs::path path(filepath);
20 if (path.extension().empty() && !ext.empty()) {
26 auto parent = path.parent_path();
27 if (!parent.empty()) {
28 fs::create_directories(parent);
30 filepath = path.string();
34 const std::string &folder_path,
35 const std::string &wildcard_pattern) {
36 fs::path root(folder_path);
37 if (!fs::exists(root) || !fs::is_directory(root)) {
38 throw_exception(std::invalid_argument(folder_path +
": no such folder"));
41 std::vector<std::string> results;
42 fs::directory_iterator end;
43 for (fs::directory_iterator it(root); it != end; ++it) {
44 if (fs::is_regular_file(*it)) {
45 const std::string filename = it->path().filename().string();
47 results.emplace_back(filename);
static void ValidateFilePath(std::string &filepath, const std::string &default_extension="")
Convenient function to validate a path before creating a file.
void throw_exception(const std::exception &e)
This file contains definitions of common data structures used in traffic manager. ...
static bool Match(const char *str, const char *wildcard_pattern)
Match str with the Unix shell-style wildcard_pattern.
static std::vector< std::string > ListFolder(const std::string &folder_path, const std::string &wildcard_pattern)
List (not recursively) regular files at folder_path matching wildcard_pattern.