I’m trying to make a program that will copy all files from one folder in to another folder.
Ex path:
From: G:\\Ex\\ExF1
To: C:\\EXAll
I’m using Visual studio express C++ as the IDE.
I have tried using this code:
bool copy_functions: :CopyAll(string InPath,string OutPath)
{
ifstream In(InPath.c_str (),ios::in|ios: :binary);
ofstream Out(OutPath.c_s tr(),ios::out|i os::binary);
if(In.is_open() == false) { cout<<InPath<<" could not be opened for copying\n\n"; }
if(Out.is_open( ) == false) { cout<<OutPath<< " could not be opened for copying\n\n"; }
if(In.is_open() == false || Out.is_open() == false)
{
getchar();
return false();
}
In.seekg(0,ios: :end);
long FileSize = In.tellg();
short* Buffer = new short(FileSize/2);
In.seekg(0,ios: :beg);
In.read((char*) Buffer,FileSize );
Out.write((char *)Buffer,FileSi ze);
delete[] Buffer;
In.close();
Out.close();
return true;
}
But I always get booth could not be opened for copying messages even thug I use the absolute paths for the folders.
Please help;
Ex path:
From: G:\\Ex\\ExF1
To: C:\\EXAll
I’m using Visual studio express C++ as the IDE.
I have tried using this code:
bool copy_functions: :CopyAll(string InPath,string OutPath)
{
ifstream In(InPath.c_str (),ios::in|ios: :binary);
ofstream Out(OutPath.c_s tr(),ios::out|i os::binary);
if(In.is_open() == false) { cout<<InPath<<" could not be opened for copying\n\n"; }
if(Out.is_open( ) == false) { cout<<OutPath<< " could not be opened for copying\n\n"; }
if(In.is_open() == false || Out.is_open() == false)
{
getchar();
return false();
}
In.seekg(0,ios: :end);
long FileSize = In.tellg();
short* Buffer = new short(FileSize/2);
In.seekg(0,ios: :beg);
In.read((char*) Buffer,FileSize );
Out.write((char *)Buffer,FileSi ze);
delete[] Buffer;
In.close();
Out.close();
return true;
}
But I always get booth could not be opened for copying messages even thug I use the absolute paths for the folders.
Please help;
Comment