Take the 2-minute tour ×

I am trying to use the windows CopyFile function to copy one file and rename it as another in a different folder. However it always returns that there's a problem with the path even though the path I am giving it is correct and both file and folder exist. What am I doing wrong?

Using "C:\Dummy.png" as the source and "C:\Dest" as the destination.

void CreateDummyItemsAssetsPNG()
    string  DummyAsset;  
    string  dummyDestination; 

    cout<<"Please Provide dummy file asset that is a .png: "; 

    cout<<"Please Provide a Destination: "; 

    vector<string>::iterator itor; 
    string fullDest; 

    for(itor = listOfItems.begin(); itor<listOfItems.end(); ++itor)
        fullDest = dummyDestination + "\\"+ (*itor)+".png"; 
        cout<<"Copy: "<<DummyAsset<<" TO: "<<fullDest<<endl; 
        if(!CopyFile(LPCTSTR(DummyAsset.c_str()),LPCTSTR(dummyDestination.c_str()),false) )
            printf("Could not copy file.\n"); 


share|improve this question
Casting c_str() to LPTSTR doesn't actually make it TSTR. –  GSerg Jul 19 '12 at 22:48
To expand on GSerg's comment: since you're using 8-bit strings, use CopyFileA instead of CopyFile. –  Harry Johnston Jul 20 '12 at 22:53
add comment

1 Answer

CopyFile() expects a file name as the second parameter, whereas you are only passing the destination directory. Specify the full name (which you seem to do in fullDest) and this should work.

share|improve this answer
add comment

Your Answer


