CopyFile ?

This doesn't work: if I get last error I get error 3. Yes The file exists and yes I have access to change it because I am the administrator.

1
2
3
4
5
6
7
8
9
int main()
{
	string a; string b;
	a = "C:\\test\\a.txt";
	b = "L:\\test\\";
	cout<< CopyFile(a.c_str(),b.c_str(),0);
        cin.ignore();
        return 0;
}


Nor does this:

1
2
3
4
5
6
7
8
{
	string a; string b;
	a = "C:\\test\\a.txt";
	b = "L:\\test\\b.txt";
	cout<< CopyFile(a.c_str(),b.c_str(),0);
        cin.ignore();
        return 0;
}


What am I doing wrong please?
Last edited on
Are you #including the needed headers? Which are the errors?
I don't get an error. Everything compiles fine. About the headers, I have all the headers I need an more (because of other bits of code that are commented out, this is the only code that I haven't commented out) even so, the headers I am using are

1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string>
#include <sys/stat.h>
#include <sys\types.h> 
#include <fstream>
#include <stdio.h>
#include <cstring>
using namespace std;


The GetLastError() function returns 3 which means "The system cannot find the path specified." The path really does exist though, and I do have permission to change it.
Are you on a POSIX or on Windows? You are including headers from both APIs
What value does CopyFile return?
Are you sure that the folder test exists on drive L?
Maybe destination folder L:\test\ doesn't exist?
EDIT: Too slow
Last edited on
Thanks for the help, but I don't know what a POSIX i'm just running on win 7 with UAC disabled as an administrator. Yes L :\test\ exists, but if it didn't exist, could I do something to make it automatically create it?

EDIT: Woo it works. I have no idea what is different but it works. Thanks
Last edited on
Topic archived. No new replies allowed.