mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-07-08 01:30:39 +08:00
fileop::join now support multiple input
This commit is contained in:
12
fileop.cpp
12
fileop.cpp
@@ -294,6 +294,18 @@ std::string fileop::join(std::string path, std::string path2) {
|
|||||||
#endif
|
#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) {
|
bool fileop::isdir(std::string path, bool& result) {
|
||||||
if (!exists(path)) {
|
if (!exists(path)) {
|
||||||
result = false;
|
result = false;
|
||||||
|
|||||||
16
fileop.h
16
fileop.h
@@ -69,6 +69,22 @@ namespace fileop {
|
|||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
std::string join(std::string path, std::string path2);
|
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.
|
* @brief check if path is an existing directory.
|
||||||
* @param path Path
|
* @param path Path
|
||||||
|
|||||||
Reference in New Issue
Block a user