Quote
In article <3A41184D.2...@datastar.com>, Kingpin <nwar...@datastar.com> wrote:
>If you copy the file yourself using -blockread/write- (which *is* the
>better solution), make sure you preserve the file date/time [for
>completeness' sake] (i.e., grab the file date/time of the original file
>and set the newly-copied file to the same).
The following should copy a file from n1 to n2. You need to supply it a
temporary buffer as well as the length of the buffer. It returns status
in error. There is no checking against overwriting existing files. The
buffer should be at least a few kilobytes.
for example:
var buffer:array[1..8192] of byte;
error:word;
filename1,filename2:string;
Copyfile(Filename1,Filename2,buffer,sizeof(buffer),error);
if error>0 then Writeln('Error ',error,' while copying');
...
You can also allocate the buffer from the heap. It is completely up to
the caller where it gets the buffer just that it provides correct buffer
and size to the copy routine.
You could try mem[$b800:0],4000 to get funny effects :-)
Procedure CopyFile(const n1,n2:String; var buff; buffsize:word
var error:word);
var f1,f2:file;
bytesread:word;
f:word;
Begin
{$i-}
Assign(f1,n1);
Assign(f2,n2);
reset(f1,1);
rewrite(f2,1);
repeat
BlockRead(f1,buff,buffsize,bytesread);
BlockWrite(f2,buff,bytesread);
until (bytesread=0) or (inoutres>0);
GetFtime(f1,t);
SetFtime(f2,t);
Close(f1);
Close(f2);
Error:=ioresult;
{$i+}
End;
If you have pre TP 7.0 remove the const from the header.
Osmo