I recently introduced a 'CopyTo' method in the File class.
It takes an outputFileName, and you just go:
Code: Select all
File f = FileOpen("sourceFile.txt", read);
if(f)
{
f.CopyTo("destFile.txt");
delete f;
}
Since it's not in any Ecere package yet, here's the source code for it:
Code: Select all
bool CopyTo(char * outputFileName)
{
bool result = false;
File f = FileOpen(outputFileName, write);
if(f)
{
byte buffer[65536];
result = true;
Seek(0, start);
while(!Eof())
{
uint count = Read(buffer, 1, sizeof(buffer));
if(count && !f.Write(buffer, 1, count))
{
result = false;
break;
}
}
}
Seek(0, start);
return result;
}
As you can see, this uses a buffer and should be significantly faster. There is also the 'BufferedFile' class (derived from 'File') which implements automatic buffering on both reading and writing, and would give you more performance on your per character implementation. However it's best to read and write bunches of bytes at once, as above.
Cheers,
Jerome