0

I am trying to work with UNC to access files on Windows on a partition that does not have a drive letter. The UNC I am trying to use (as returned by mountvol) is

\\?\Volume{6ed63a9f-b672-4f57-8c22-8dd824dd793e}\

Using powershell Get-ChildItem -Literalpath or even dir -l (with the UNC above) works perfectly well.

But using std::filesystem I get an exception that says Invalid Argument. I try \\?\Volume{6ed63a9f-b672-4f57-8c22-8dd824dd793e}\data\somefilename and \\?\Volume{6ed63a9f-b672-4f57-8c22-8dd824dd793e}\\data\somefilename

without success. What is the correct format?

EDIT

Well, using the fileapi from Windows (CreateFile and ReadFile) works as expected. So my string that identifies the file is perfect.

The only issue is that I would really have preferred to use std::filesystem, since this is what I use in my file access wrapper.

Is this a bug in mingw-w64? I am using x86_64-w64-mingw32-g++ (GCC) 10-posix 20220113 on Ubuntu 22-04

Claude
  • 51
  • 2
  • 7
  • 1
    How are you specifying the path in the code? You need to use two backslashes for each one in the path if you are not using a raw string literal, i.e `C:\foo\bar.baz` -> `C:\\foo\\bar.baz` – NathanOliver Sep 02 '22 at 16:58
  • I am using a std::string in std::filesystem::path and then into some operation (e.g. std::filesystem::exists(path)). When I access a file, based on a drive letter as the root-name, the string is "c:\foo\bar.baz", so no double backslashes, and all is fine. – Claude Sep 02 '22 at 18:20
  • It only "works" probably because you aren't accidently using an [escape sequence](https://en.cppreference.com/w/cpp/language/escape). In `\\?\V...` the `\V` is an escape sequence for a vertical tab, so without using `\\\\?\\V...` you wont get the correct path. – NathanOliver Sep 02 '22 at 18:27
  • OH, I left out the escaping thing for the literal in my comment. That is because in fact I am reading the path from a test file so the escaping thing is already taken are of. But when testing with a literal I do use the escape thing as required. In any case, I output the string to the screen too and if I cut and paste it to a dir command (dir -l 'pastehere' to be precise) all is good. – Claude Sep 02 '22 at 19:56

0 Answers0