unit UShFile;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, AppEvnts;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    ESource: TEdit;
    ETarget: TEdit;
    BFind1: TButton;
    BFind2: TButton;
    RadioGroup1: TRadioGroup;
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    RadioGroup2: TRadioGroup;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    RadioGroup3: TRadioGroup;
    ApplicationEvents1: TApplicationEvents;
    procedure Button1Click(Sender: TObject);
    procedure BFind1Click(Sender: TObject);
    procedure BFind2Click(Sender: TObject);
    procedure ApplicationEvents1ShowHint(var HintStr: String;
      var CanShow: Boolean; var HintInfo: THintInfo);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses ShellAPI, StrUtils;

procedure TForm1.Button1Click(Sender: TObject);
var SHF: TSHFileOpStruct;
    SFrom, STo: string;
begin
 SFrom := ESource.Text + #0#0;
 SFrom := AnsiReplaceStr(SFrom, ';', #0);
 STo := ETarget.Text + #0#0;
 with SHF do
 begin
  Wnd := 0;
  pFrom := PChar(SFrom);
  pTo := PChar(STo);
  fFlags := FOF_ALLOWUNDO;
  if not CheckBox1.Checked
   then fFlags := fFlags or FOF_NOCONFIRMATION;
  if CheckBox2.Checked
   then fFlags := fFlags or FOF_NOCONFIRMMKDIR;
  case RadioGroup1.ItemIndex of
   0: wFunc := FO_COPY;
   1: wFunc := FO_MOVE;
   2: wFunc := FO_RENAME;
   3: wFunc := FO_DELETE;
  end;
  if RadioGroup2.ItemIndex = 1
   then fFlags := fFlags or FOF_RENAMEONCOLLISION;
  if RadioGroup3.ItemIndex = 2
   then fFlags := fFlags or FOF_SILENT
  else if RadioGroup3.ItemIndex = 1
   then begin
    fFlags := fFlags or FOF_SIMPLEPROGRESS;
    lpszProgressTitle := 'Пожалуйста, подождите';
   end;
 end;
 if SHFileOperation(SHF) <> 0
  then if SHF.fAnyOperationsAborted
    then ShowMessage('Выполнение операции прервано пользователем')
    else ShowMessage('Ошибка выполнения операции')
  else ShowMessage('Операция успешно завершена');
end;

procedure TForm1.BFind1Click(Sender: TObject);
var i: integer;
begin
 OpenDialog1.Options := OpenDialog1.Options + [ofAllowMultiSelect];
 if OpenDialog1.Execute
 then
   for i:=1 to OpenDialog1.Files.Count do
     ESource.Text := ESource.Text + OpenDialog1.Files.Strings[i-1] + ';';
end;

procedure TForm1.BFind2Click(Sender: TObject);
begin
 OpenDialog1.Options := OpenDialog1.Options - [ofAllowMultiSelect];
 if OpenDialog1.Execute
 then ETarget.Text := OpenDialog1.FileName;
end;

procedure TForm1.ApplicationEvents1ShowHint(var HintStr: String;
  var CanShow: Boolean; var HintInfo: THintInfo);
begin
if (HintInfo.HintControl.ClassName = 'TEdit')
  then if (Label1.Canvas.TextWidth(
              (HintInfo.HintControl as TEdit).Text) >
              (HintInfo.HintControl as TEdit).ClientWidth)
  then begin
    HintStr:=(HintInfo.HintControl as TEdit).Text;
    ApplicationEvents1.CancelDispatch;
  end;
end;

end.
