I'm trying to create a program that will copy a folder automatically every 240 minute (or every 4 hour). I found the CopyFile function would suit my needs.
The problem I am experiencing is that no matter what type of string or character array I put into the first two arguments wont get accepted.
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
usingnamespace std;
int timer();
int main()
{
while (1)
{
constchar * f = "test.txt";
constchar * newF = "test1.txt";
int timerV = timer();
if (timerV == 240) //240 minutes
if (CopyFile(f, newF, false))
{
}
else
cout << "Failed to execute copy.\n";
else
cout << "Failed to execute copy.\n";
}
cin.get();
return 0;
}
int timer()
{
int time = 0;
while (time < 240) //240 minutes
{
Sleep(60000); //1 minute
time++; //add 1
}
return time;
}
I've tried using a regular character array, a string object, const char, like I used in this example, and also typing the string directly into the function, not using a variable, like so:
CopyFile("test.txt", "test1.txt", false)
When trying to compile any of these I get the error "argument of type (type) is incompatible with parameter of type "LPCWSTR""
Another alternative - and this applies to many windows functions, is to add the suffix A for ordinary characters and W for wide-characters. Hence CopyFile becomes CopyFileA.
1 2 3 4
if (!CopyFileA(f, newF, false))
{
cout << "Failed to execute copy.\n";
}
As an aside, if you're using a recent MS compiler, it will have support for the experimental C++ filesystem library and you can just use that, without having to worry about unicode/wide/ordinary/etc.