-
July 2nd, 2009, 08:39 PM
#1
CopyFile() Function
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) )
{
}
else
{
cout << "Could not copy file";
cout << GetLastError();
}
system("pause");
return 0;
}
Any help is appreciated. Thanks!
-
July 2nd, 2009, 09:03 PM
#2
Re: CopyFile() Function
I have to guess.
Perhaps bla2 doesn't exist?
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).
-
July 2nd, 2009, 09:11 PM
#3
Re: CopyFile() Function
Problem solved, I forgot to change the setting in Visual Studio to not use unicode character set.
Thanks again
Last edited by TeachMeProgPl0x; July 3rd, 2009 at 12:19 AM.
-
July 3rd, 2009, 05:17 AM
#4
Re: CopyFile() Function
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.
-
July 3rd, 2009, 08:45 AM
#5
Re: CopyFile() Function
Use the code tags, you'll get much more help since the code will be much more legible.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|