复制文件的Delphi代码示例,用自定义的窗体来实现传统的复制文件功能,主要是展示在Delphi下如何定义复制文件的函数,打基础的代码。复制的核心代码:
if edtSFile.Text <> '' then
begin
AssignFile(FormF,edtSFile.Text);
Reset(FormF,1);
if edtTFile.Text <> '' then
begin
AssignFile(ToF,edtTFile.Text);
ReWrite(ToF,1);
lbMesg.Caption := lbMesg.Caption IntToStr(FileSize(FormF)) 'bytes已经拷贝完成!';
repeat
BlockRead(FormF,Buf,SizeOf(BUf),NumRead);
BlockWrite(ToF,Buf,NumRead,NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FormF);
CloseFile(ToF);
ShowMessage('文件复制完成!');
end else ShowMessage('源文件有问题!');
end else ShowMessage('目标文件有问题!');
end;
1