Dear all,

I am trying to use WIN32 API "CopyFile" to copy a file from a remote machine to local.

bRet = CopyFile(src, dest, false);

"dest" is defined as

dest = "\\\\desk\\data\\1.txt";

But this operation always fails. Could anybody give me a little hint? Thanks!

I can read / write that folder. Just wonder why API fails?

Do you have write permissions on that computer and directory? Try to copy manually and see if it works.

This worked for me, where VICTOR is another computer on my LAN.

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
    string src = "C:\\Users\\Ancient_Dragon\\Documents\\test.txt";
    string dest = "\\\\VICTOR\\SharedDocs\\test.txt";

    BOOL rval = CopyFile(src.c_str(), dest.c_str(), FALSE);
    cout << rval << "\n";
}

Do not know why it did not work for me.

GetLastError() returns 3. What does 3 mean?

BTW, if I map the shared folder as a network drive like \\desk\data -> X:\, the following code will work.

dest = "Y:\\1.txt";
bRet = CopyFile(src, dest, false);

This worked for me, where VICTOR is another computer on my LAN.

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
    string src = "C:\\Users\\Ancient_Dragon\\Documents\\test.txt";
    string dest = "\\\\VICTOR\\SharedDocs\\test.txt";

    BOOL rval = CopyFile(src.c_str(), dest.c_str(), FALSE);
    cout << rval << "\n";
}

GetLastError() returns 3. What does 3 mean?

GetLastError()'s error codes are defined in <winerror.h>, you can always lookup them there. 3 means ...

//  The system cannot find the path specified.
//
#define ERROR_PATH_NOT_FOUND             3L

So, for some reason (unknown to me, sorry), apparently the network path is not found.

This article has been dead for over six months. Start a new discussion instead.