Last active
August 25, 2022 20:31
-
-
Save voidbar/1a9ff778703c175b241e2aa488dd144b to your computer and use it in GitHub Desktop.
Using std::filesystem trick to convert windows short path into long 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 <iostream> | |
#include <format> // C++20 Required | |
namespace fs = std::filesystem; | |
std::string to_long_path(const std::string& short_path) { | |
return fs::canonical(short_path).string(); | |
} | |
int main() { | |
std::string short_path{"C:\\PROGRA~1"}; | |
auto long_path = to_long_path(short_path); | |
std::cout << std::format(R"(Short Path: "{}". Long Path Using std::fs: "{}")", short_path, long_path); | |
// Output: Short Path: "C:\PROGRA~1". Long Path Using std::fs: "C:\Program Files" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment