In the application software that is open, sometimes we copy some files (such as backing up the database, making the installer), but some languages that are commonly used do not provide a procedure or function that can directly copy the files. To this end, I used Delphi to develop a file copy process to provide a dynamic connection library Copy.dll, the output process is copyfile. Because the DLL has many advantages, such as simplifying programming and running fast, and is not limited by the programming language,
Delphi written by the Copf.dll is also VB, VC and other object-oriented language for static or dynamic calls, people and conveniently in the program to achieve file copies.
The attached source procedure is as follows:
library copf;
uses
SysUntils,Classes;
procedure copyfile(Sfname.Dfname:string):far;export;//带路径的文件名;
Var
Sourcef,Destinef:file;
NumRead,NumWritten:Integer;
Buf:array[1..4096] of char;//定义缓冲区;
Begin
AssignFile(Sourcef,dfname);
Reset(Sourcef,1);
AssignFile(Destinef,1);
Rewrite(Destinef,1);
Repeat
BlockRead(Sourcef,Buf,SizeOf(Buf),Numread);//读源文件
BlockWrite(destinef,buf,NumRead,NumWritten);//写目标文件;
Until (Numread=0) or (Numwritten<>numread);
closeFile(soucef);
Closefile(destinef);
end;
Esports
copyfile;//output process;
End
The above source program compiles and then generates Copf.dll
Now, for example, static invocation:
unit Name;
interface
uses
Windows...;
Type
Tzcform=class(Tform)
...
end;
var
Form1:Tform1;
implementation
Procedure copyfile(Sfname,dfname:string);far;external'c:\copf';//DLL路径名;
{$R *.DFM}
Procedure Tform1.CopyButtonclick(sender:tobject);
Begin
...
if fileesist(sfname)//如果源文件;
then copyfile(sfname,dfname);
... end;