16#include <boost/filesystem/operations.hpp>
22namespace fs = boost::filesystem;
31 fs::path path(filepath);
32 if (path.extension().empty() && !ext.empty()) {
38 auto parent = path.parent_path();
39 if (!parent.empty()) {
40 fs::create_directories(parent);h
42 filepath = path.string();将修正后的路径转换回字符串并赋值给filepath
47 const std::string &folder_path,
48 const std::string &wildcard_pattern) {
50 fs::path root(folder_path);
52 if (!fs::exists(root) || !fs::is_directory(root)) {
53 throw_exception(std::invalid_argument(folder_path +
": no such folder"));
56 std::vector<std::string> results;
57 fs::directory_iterator
end;
58 for (fs::directory_iterator it(root); it !=
end; ++it) {
59 if (fs::is_regular_file(*it)) {
60 const std::string filename = it->path().filename().string();
62 results.emplace_back(filename);
auto end() const noexcept
static std::vector< std::string > ListFolder(const std::string &folder_path, const std::string &wildcard_pattern)
列出 folder_path 中匹配 wildcard_pattern 的常规文件 (不递归)。
static void ValidateFilePath(std::string &filepath, const std::string &default_extension="")
在创建文件之前验证路径的方便函数。
static bool Match(const char *str, const char *wildcard_pattern)
Match str with the Unix shell-style wildcard_pattern.
void throw_exception(const std::exception &e)