CopyFile

I am not sure why CopyFile is failing. Below is code snippet. Can you help me debug? copyfile fnc returns Zero. permPath is Temp dir loaction on C:\ and I checked it is fine.

if ((hFind = FindFirstFile(L"*", &fd)) != INVALID_HANDLE_VALUE)
      {
            do
            {

            if (wcscmp(CAU_PKG_SIGN_FILE_NAME, fd.cFileName) &&
                        wcscmp(L".", fd.cFileName) &&
                        wcscmp(L"..", fd.cFileName) )
                  {
                        wstring newFileName = permPath + wstring(fd.cFileName);
                        if (!CopyFile(fd.cFileName,(wchar_t*) newFileName.c_str(), FALSE))
                        {
                                                                                          permPath.erase();
                              break;
                        }
                  }
            }
            while (FindNextFile(hFind, &fd));
            FindClose(hFind);
      }
LVL 2
pb_indiaAsked:
Who is Participating?
 
AxterCommented:
Run it in debug mode, and look at the value of fd.cFileName and newFileName

You should not need to use the (wchar_t*) cast, and I recommend that you remove it.
It only serves to prevent the compiler from doing it's job in type checking.    
0
 
AxterCommented:
If you're current working directory is not in the same location as where the file is at, then you'll need to give a full path and file name to CopyFile API for the source.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.