fileop::join now support multiple input

This commit is contained in:
2025-05-17 13:23:52 +08:00
parent 2480b6ea8a
commit f4213c702c
2 changed files with 28 additions and 0 deletions

View File

@@ -294,6 +294,18 @@ std::string fileop::join(std::string path, std::string path2) {
#endif
}
std::string fileop::join(std::initializer_list<std::string> paths) {
std::string path;
for (auto it = paths.begin(); it != paths.end(); it++) {
if (it == paths.begin()) {
path = *it;
} else {
path = join(path, *it);
}
}
return path;
}
bool fileop::isdir(std::string path, bool& result) {
if (!exists(path)) {
result = false;

View File

@@ -69,6 +69,22 @@ namespace fileop {
* @return result
*/
std::string join(std::string path, std::string path2);
/**
* @brief Join multiple pathname components
* @param paths List of pathname components
* @return Joined path string
*/
std::string join(std::initializer_list<std::string> paths);
/**
* @brief Join multiple pathname components (variadic template version)
* @tparam Args Additional pathname component types
* @param paths All pathname components
* @return Joined path string
*/
template<typename... Args>
std::string join(Args... paths) {
return join({std::forward<Args>(paths)...});
}
/**
* @brief check if path is an existing directory.
* @param path Path