Last active
July 7, 2024 16:08
-
-
Save raspiduino/1eac926863463f68a7c5c841be2d06f3 to your computer and use it in GitHub Desktop.
Alternative to parent_path() on std::filesystem::path with Windows style path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <filesystem> | |
#include <string> | |
#include <iostream> | |
#include <regex> | |
namespace fs = std::filesystem; | |
int main() { | |
fs::path p = "e:\\abc\\xyz.txt"; | |
std::string s = p.string(); | |
s = std::regex_replace(s, std::regex("\\\\"), "/"); | |
std::string s2 = fs::path(s).remove_filename().string(); | |
s2 = std::regex_replace(s2, std::regex("/"), "\\"); | |
fs::path n = s2; | |
std::cout << "converted " << p << " to " << s << " then to " << n << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment