Copiando arquivos usando curingas [*.*]

 

procedure TForm1.Button2Click(Sender: TObject);

var

  SR: TSearchRec;

  I: integer;

  Origem, Destino: string;

begin

   I := FindFirst('c:\Origem\*.*', faAnyFile, SR);

   while I = 0 do

   begin

     if (SR.Attr and faDirectory) <> faDirectory then

     begin

       Origem := 'c:\Origem\' + SR.Name;

       Destino := 'c:\Destino\' + SR.Name;

       if not CopyFile(PChar(Origem), PChar(Destino), true) then

         ShowMessage('Erro ao copiar ' + Origem + ' para ' + Destino);

     end;

     I := FindNext(SR);

   end;

end;

Observações

No exemplo acima, se o arquivo já existir no destino, a função falha (não copia). Para que a função possa sobreescrever o arquivo destino (caso exista), altere o último parâmetro de CopyFile para false.