Posted on 2006-04-21
Medium Priority
Last Modified: 2008-02-01
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)

            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))
            while (FindNextFile(hFind, &fd));
Question by:pb_india
  • 2
LVL 30

Accepted Solution

Axter earned 500 total points
ID: 16512075
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.    
LVL 30

Expert Comment

ID: 16512084
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.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question