diff --git a/fileop.cpp b/fileop.cpp index ab2f910..977ce98 100644 --- a/fileop.cpp +++ b/fileop.cpp @@ -294,6 +294,18 @@ std::string fileop::join(std::string path, std::string path2) { #endif } +std::string fileop::join(std::initializer_list 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; diff --git a/fileop.h b/fileop.h index 81686aa..35f3743 100644 --- a/fileop.h +++ b/fileop.h @@ -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 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 + std::string join(Args... paths) { + return join({std::forward(paths)...}); + } /** * @brief check if path is an existing directory. * @param path Path