jurs:
but do read bigger buffers of bytes, i.e.
- read buffer of 64 bytes
- write buffer of 64 bytes
In case the file size is not a multiple of 64, the last read/write operation will be less than 64 bytes.Whether your file copy is slow or fast, is just a matter of clever coding.
Yeah, but to find what you need seems to be a 'mission impossible'. It goes something like this:
- Go to the SD library reference.
- Find something related to reading files; e.g. read.
- Hmm, no example; that sucks.
- Hmm, no mentioning of a read function / method that takes one or more arguments.
- Go back to SD library reference.
- Check the Read/Write example
- Stupid example that I already based my code on.
- Back to read.
- Hmm, it says something about 'read() inherits from the Stream utility class'.
- Lets see what we they say there.
- Ah, there is a readBytesfunction / method. Maybe that will do the trick.
That way I came to the below (partial) code based on OP's code; I don't know if it works because I don't have an SD shield but I suspect it does.
if (File1) {
File2 = SD.open(file_name2, FILE_WRITE);
if (File2) {
while (File1.available() > 0)
{
int i = File1.readBytes(ibuffer, 64);
File2.write(ibuffer, i);
}
// done, close the destination file
File2.close();
}
Serial.println("Done copying...");
// done, close the source file
File1.close();
}
In the three months that I have been using an Arduino I have never been impressed with the reference.
Why I survive the reference system is that I know what should be possible (based on previous experience in e.g. C (notC+++) under DOS and Linux) and hence what to search for (e.g. using google).
Why can the Serial reference provide a link to Serial.readBytes but the SD library reference can't.
I hope for OP that the above code works but no guarantee.