SHFileOperation Demo

//
// SHFILE.PAS
// Shows how to copy files using SHFileOperation
//
unit SHFile;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ShellAPI, StdCtrls, ExtCtrls, FileCtrl;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Button2: TButton;
    FileListBox1: TFileListBox;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
 FO      : TSHFileOpStruct;
 Aborted : Bool;
begin
 Aborted := False;
 With FO do
  Begin
   Wnd   := Handle;
   wFunc  := FO_COPY;
   pFrom  := 'D:\WELCOME.AVI';
   pTo    := 'C:\';
   fFlags := 0;
   fAnyOperationsAborted := Aborted;
  End;
 try
  SHFileOperation(FO);
 finally
  if Aborted Then ShowMessage('Error')
 end;
end;
{Show Icon associated with this file or file type}
procedure TForm1.Button2Click(Sender: TObject);
var
 SFI : TShFileInfo;
begin
 SHGetFileInfo(PChar('d:\windows\'+Edit1.Text), 0, SFI, SizeOf(SFI),
SHGFI_ICON);
 If SFI.hIcon <> 0 Then Image1.Picture.Icon.Handle := SFI.hIcon;
end;
end.