Hi, Im trying to write a program that will simply copy a text file from one folder located on my C drive, to another, however, the CopyFile() function does not copy the file, and after tracing the error with GetLastError, I get a "Can not copy file" error. I have tried altering my directory by using double backslashes, however, it does not seem to work either. Here is my code:
#include <iostream>
using namespace std;
#include <windows.h>
int main()
{
if ( CopyFile( (LPCWSTR("c:\Documents and Settings\User\Desktop\bla\Doc1.txt")),
(LPCWSTR("c:\Documents and Settings\User\Desktop\bla2\Doc1.txt")),
0) )
{
You'd have to make the destination directory before you perform the copy.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
This is the syntax if you want to use UNICODE.
if ( CopyFile( (_T("c:\\Documents and Settings\\User\\Desktop\\bla\\Doc1.txt")),
(_T("c:\\Documents and Settings\\User\\Desktop\\bla2\\Doc1.txt")),
0) )
Actually it will work both for unicode and non-unicode builds.
«_Superman_» I love work. It gives me something to do between weekends.
Bookmarks