Delphi Copy directory (including subdirectories) method

Source: Internet
Author: User

To implement a directory-level copy, you can take advantage of the Windows API function SHFileOperation (), whose function is declared as follows: Winshellapi int WINAPI shfileoperation (lpshfileopstruct LP    FILEOP);    Example: Create a new project with the following program example: Unit Unit1;   Interface uses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls,shellapi;  Note: You must refer to the Shellapi cell type TForm1 = Class (Tform) Button1:tbutton;  Procedure Button1Click (Sender:tobject);    Private {Private declarations} public {public declarations} end;    var Form1:tform1;  Implementation {$R *.DFM} procedure Tform1.button1click (Sender:tobject);  var opstruc:tshfileopstruct;  Frombuf,tobuf:array[0..128]of Char;  Begin Fillchar (frombuf,sizeof (FROMBUF), 0);  Fillchar (Tobuf,sizeof (TOBUF), 0);    Assume that all files under the C:\TEMP1 directory are copied to the C:\TEMP2 directory strpcopy (frombuf, ' c:\temp1\*.* ');  (\*.*) can be removed strpcopy (tobuf, ' C:\temp2 ');      With Opstruc do begin wnd:=handle;      Wfunc:=fo_copy;      pfrom:[email protected];      pto:[email protected]; Fflags:=fOf_noconfirmation or fof_renameoncollision;      Fanyoperationsaborted:=false;      Hnamemappings:=nil;  Lpszprogresstitle:=nil;  End  SHFileOperation (OPSTRUC);    End        End.      Through this program, you can copy a subdirectory and all of its following files (including sub-subdirectories) to another subdirectory, if the target directory does not exist, it will be automatically created, thereby actually some of the functions of automatic backup.

  

Delphi Copy directory (including subdirectories) method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.