Hi every body how are you? I'm trying to write a program in C++ that does the following: scans a folder for files, selects one of these files at random, copies the selected file to a prespecified folder, then renames this file to a another predifined name. So far I've the part that scans the folder selects a random file, I need help in copying this selected file to a another folder. Can any one please help? It will be greatly appreciated.
So far I have the following code:
Code:
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#include<iostream>
using namespace std;
int main()
{
srand(time(0));
WIN32_FIND_DATA buf;
HANDLE find=FindFirstFile("*.txt",&buf);
if(find==INVALID_HANDLE_VALUE)
{
cout<<"No *.txt file"<<endl;
system("pause");
return 0;
}
char*file_found=buf.cFileName;
do
{
if(rand()%3==0)//1 case out of 3
{
file_found=buf.cFileName;
break;
}
}
while(FindNextFile(find,&buf));
FindClose(find);
cout<<"I selected "<<file_found<<endl;
system("pause");
return 0;
}