Posted on 2006-04-21
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
    LVL 30

    Accepted Solution

    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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete C++ Projects

    Source the talented Expert Exchange community
    for top quality work on your C++ projects.

    Hire the best. Collaborate easily. Get quality work.

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now