How can I copy all the files from one folder to another folder?

    3 answers 3

    1) Get all the files from the specified directory using the combination findfirst-> findnext-> findclose:

    procedure copypast(dir:string; to_dir:string); var fn:TSearchRec; begin dir:=includetrailingbackslash(dir); to_dir:=includetrailingbackslash(to_dir); if findfirst(dir+'*',faanyfile,fn)<>0 then exit; // * - любые файлы copyfile(Pchar(dir+fn.name),Pchar(to_dir+fn.name),true); while findnext(fn)=0 do copyfile(Pchar(dir+fn.name),Pchar(to_dir+fn.name),true); findclose(fn); end; 

      WinAPI means of WinAPI : see section File Management Functions . There is a complete set of functions, CopyFile , FindFirstFile , FindNextFile , etc.

        And so go? Module code:

         unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl, Buttons, Gauges; type TForm1 = class(TForm) BitBtn1: TBitBtn; GroupBox1: TGroupBox; DirectoryListBox1: TDirectoryListBox; FileListBox1: TFileListBox; DriveComboBox1: TDriveComboBox; GroupBox2: TGroupBox; DirectoryListBox2: TDirectoryListBox; FileListBox2: TFileListBox; DriveComboBox2: TDriveComboBox; GaugeFile: TGauge; GaugeAll: TGauge; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.BitBtn1Click(Sender: TObject); Var F1, F2: File Of Char; Buf: Array[1..2048] Of Char; SizeFile, SizeRead: Int64; ColRead, ColWrite: Integer; i, n: Word; FName: String; begin N:=FileListBox1.Items.Count-1; GaugeAll.MaxValue:=N+1; {$I-} For i:=0 To N Do Begin FName:=DirectoryListBox1.Directory+'\'+FileListBox1.Items.Strings[i]; AssignFile(F1, FName); AssignFile(F2, DirectoryListBox2.Directory+'\'+FileListBox1.Items.Strings[i]); Try ReSet(F1); SizeFile:=FileSize(F1); ReWrite(F2); ColRead:=0; ColWrite:=0; SizeRead:=0; Screen.Cursor:=crHourGlass; While (ColRead=ColWrite) Do Begin BlockRead(F1, Buf, SizeOf(Buf), ColRead); If (ColRead=0) Then Break; BlockWrite(F2, Buf, ColRead, ColWrite); SizeRead:=SizeRead+ColRead; GaugeFile.Progress:=Round(100*SizeRead/SizeFile); Application.ProcessMessages; End; GaugeAll.Progress:=GaugeAll.Progress+1; Screen.Cursor:=crDefault; Finally CloseFile(F1); CloseFile(F2); End; End; {$I+} end; end. 

        Program interface: alt text

        • Thank you very much!!! True, I would like through the OpenDialog component or whatever it is called? !! - delphikettle
        • Oh ... tin =) And you wrote a whole program for this? - AseN
        • Nuuu .... not only for this !!! - delphikettle