Does anyone know a function that will allow you to copy one file to another location?
CopyFile(File, File2);
Does anyone know a function that will allow you to copy one file to another location?
CopyFile(File, File2);
procedure SAFECOPY (fromFile, toFile : string);
this function likely reads the disk 64 times per 4096 bytes instead of 1x
procedure SAFECOPY (fromFile, toFile : string);
this only copies 64 bytes at a time (should be something closer to the filesystem block size, or if it's unknown the best guess is 4096). i.e: thi function likely reads the disk 64 times per 4096 bytes instead of 1x
On 02 Sep 22 21:22:49, Chad Adams said the following to All:
Does anyone know a function that will allow you to copy one file to an location?
CopyFile(File, File2);
procedure SAFECOPY (fromFile, toFile : string);
type bufferType = array [1..64] of char;
type bufferTypePtr = ^bufferType; { Use the heap }
var bufferPtr : bufferTypePtr; { for the buffer }
f1, f2 : file;
bufferSize, readCount, writeCount : word;
fmSave : byte; { To store the filemode }
begin
bufferSize := SizeOf(bufferType);
New (bufferPtr); { Create the buffer, on the heap }
fmSave := FileMode; { Store the filemode }
FileMode := 0; { To read also read-only files }
Assign (f1, fromFile);
{$I-} Reset (f1, 1); { Note the record size 1, important! }
if IOResult <> 0 then exit; { Does the file exist? }
Assign (f2, toFile);
{$I-} Rewrite (f2, 1); { Open the target }
if IOResult <> 0 then exit;
repeat { Do the copying }
BlockRead (f1, bufferPtr^, bufferSize, readCount);
{$I-} BlockWrite (f2, bufferPtr^, readCount, writeCount);
if IOResult <> 0 then begin close (f1); exit; end;
until (readCount = 0) or (writeCount <> readCount);
close (f1); close (f2);
FileMode := fmSave; { Restore the original filemode }
Dispose (bufferPtr); { Release the buffer from the heap }
end; (* safecopy *)
Nick
--- Renegade vY2Ka2
* Origin: Joey, do you like movies about gladiators? (1:229/426)
I'm sure the whole thing can be improved, it was an example from a collect of code dating back to... TP 5.5 I think.
Sysop: | StingRay |
---|---|
Location: | Woodstock, GA |
Users: | 29 |
Nodes: | 15 (0 / 15) |
Uptime: | 34:21:25 |
Calls: | 591 |
Calls today: | 1 |
Files: | 359 |
Messages: | 227,762 |
Posted today: | 1 |