1. Home
  2. Computing & Technology
  3. Delphi Programming

Copying Group of Files using Delphi
with Standard Animation Dialog (SHFileOperation)

By Zarko Gajic, About.com

The following example demonstrates using the SHFileOperation function to copy a group of files and display a progress dialog. You can also use the following flags to delete, move and rename a group of files.

FO_COPY
FO_DELETE
FO_MOVE
FO_RENAME

Note: The buffer that contains the file names to copy must end with a double null terminating character

The following example copies three files to 'e' drive.
uses ShellAPI;

procedure TForm1.Button1Click(Sender: TObject) ;
var
 Fos : TSHFileOpStruct;
 Buf : array[0..4096] of char;
 p : pchar;
 sDest : string;
begin
  FillChar(Buf, sizeof(Buf), #0) ;
  p := @buf;
  p := StrECopy(p, 'C:\FirstFile.ext1') + 1;
  p := StrECopy(p, 'C:\SecondFile.ext2') + 1;
  StrECopy(p, 'C:\ThirdFile.ext3') ;

  sDest := 'e:\';

  FillChar(Fos, sizeof(Fos), #0) ;
  with Fos do
  begin
    Wnd := Handle;
    wFunc := FO_COPY;
    pFrom := @Buf;
    pTo := sDest;
    fFlags := 0;
  end;
  if ((SHFileOperation(Fos) <> 0) or (Fos.fAnyOperationsAborted <> false)) then ShowMessage('Cancelled')
end;

Delphi tips navigator:
» Long ListBox entries as hints
« Capture the output from a DOS (command/console) Window

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Copying Group of Files using Delphi with Standard Animation Dialog (SHFileOperation)

©2009 About.com, a part of The New York Times Company.

All rights reserved.