1
votes

So I'm trying to simulate a distant file opening, which is pointing back to my computer, however i keep failing with error 3 (FILE_NOT_FOUND). I went through the following documentation regarding network usage, but it didn't work either.

hFile1 = ::CreateFile(LR"(\\172.17.12.172\C$\Develop\Code\File.txt)", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (INVALID_HANDLE_VALUE == hFile1)
{
    LOG_ERROR(L"Failed opening file with: " << GetLastError());
    break;
}
  1. The FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE flags are for the GetFileInformationByHandle which is used later on, i compare file paths.
  2. I tried opening \\172.17.12.172\C$\Develop\Code\File.txt using notepad, it worked.

172.17.12.172 is my local ip address.

1
Why the () in the path? - deviantfan
I used the R prefix, so i wouldn't need to use escape chars - igal k
Escape chars have nothing to do with it. Parenthesis just don“t belong there. - deviantfan
@deviant the delimiters are "( and )" - David Heffernan

1 Answers

1
votes

The syntax of your file name is fine. That the error code is FILE_NOT_FOUND rather than some other error means that the directory is found, but no file within that directory can be located.

You should be able to open a file with a path of that form using CreateFile. If you really can open the file with that path using Notepad, then you will be able to do the same using CreateFile, so long as you pass the same file name.

So the most plausible explanation is that you simply made a typographical error. I see no reason to look beyond the obvious conclusion suggested by FILE_NOT_FOUND. There is no file of that name.