For the below code:
std::error_code ec;
auto long_path = std::filesystem::canonical("W:\\31\\arawat.fielsystem_default_check\\matlab\\check_std\\check_std\\").string();
I am getting the value of long_path
as:
"\\\\bgl-zp31-cifs\\vmgr\\sbs31\\arawat.fielsystem_default_check\\matlab\\check_std\\check_std"
std::filesystem::canonical()
is converting the path to a network UNC path. Is there any way to prevent it, or to get the original drive letter path back from a network path?
I have tried using Windows APIs like WNetGetUniversalName()
, etc.
For the below code:
std::error_code ec;
auto long_path = std::filesystem::canonical("W:\\31\\arawat.fielsystem_default_check\\matlab\\check_std\\check_std\\").string();
I am getting the value of long_path
as:
"\\\\bgl-zp31-cifs\\vmgr\\sbs31\\arawat.fielsystem_default_check\\matlab\\check_std\\check_std"
std::filesystem::canonical()
is converting the path to a network UNC path. Is there any way to prevent it, or to get the original drive letter path back from a network path?
I have tried using Windows APIs like WNetGetUniversalName()
, etc.
1 Answer
Reset to default 2is there any way to prevent it ...
Yes, just use std::filesystem::path
:
auto long_path = std::filesystem::path("...");
If the path contains relative elements and you'd like to resolve them into a full path, use std::filesystem::absolute
:
auto long_path = std::filesystem::absolute("...");
Example:
#include <iostream>
#include <filesystem>
int main()
{
auto long_path = std::filesystem::path(R"aw(N:\proj\stackoverflow\..)aw");
std::cout << long_path << '\n';
std::cout << std::filesystem::absolute(long_path) << '\n';
std::cout << std::filesystem::canonical(long_path) << '\n';
}
Possible output:
"N:\\proj\\stackoverflow\\.."
"N:\\proj"
"\\\\192.168.1.4\\ted\\proj"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744845833a4596829.html
W
drive is a network drive? And why is this a problem? – Some programmer dude Commented Mar 10 at 12:55