delphi中有拷贝文件的过程或函数吗?(20分)

应该是没有吧,

好像只能用file的Read和Write的。
 
没有!
我都是通过将文件一个个字节读出来,再写到目标文件中去的。
速度倒没有什么差别,还另有一个好处:你可以显示进程条当前多少字节或百分
比被复制了。

var
DesFile,SourFile : File;
Buf : Byte;
begin
AssignFile(SourFile,"源文件名");
Reset(SourFile,1); //1表示是一个一个字节地读
AssignFile(DesFile,"目标文件名");
Rewrite(DesFile,1);
while not Eof(SourFile) do begin
BlockRead(SourFile,Buf,SizeOf(Byte));
BlockWrite(DesFile,Buf,SizeOf(Byte));
end;
CloseFile(SourFile);
CloseFile(DesFile);
end;
 
WIN32API 已经提供了CopyFile(),
Inprise可不愿做重复劳动。
 
看看实例文件delphi/demo/doc/Filmanex/
 
直接使用API函数CopyFile比较方便;
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);

如:CopyFile(PChar('C:/autoexec.bat'),
PChar('D:/Backup/autoexec.bat') ,
True);
 
DEMO/DOC/FILUTILS.PAS 里有个 COPYFILE
 
多人接受答案了。
 
顶部