File corrupted when copying from one folder to another

1

I'm locating and saving the files in a listbox1, as follows:

procedure Localizar(DIR,ARQ: string; LIST: TStrings);
var
SR: TSearchRec;
begin
{Garante a barra no final do diretório}
if DIR[length(DIR)] <> '\' then
DIR := DIR + '\';

{Encontra os arquivos e diretórios segundo o definido em ARQ}
if FindFirst(DIR + ARQ, faAnyFile, SR) = 0 then
repeat
if (SR.Name <> '.') and (SR.Name <> '..') then
begin
LIST.Add(DIR + SR.Name); //Grava o arquivo/diretório encontrado num TStrings
Application.ProcessMessages; //Essa linha pode ser eliminada se executar a procedure numa outra thread
end
until FindNext(SR) <> 0;

{Busca os subdiretórios de DIR}
if FindFirst(DIR + '*.*', faAnyFile, SR) = 0 then
repeat
if SR.Attr = faDirectory then
begin
if (SR.Name <> '.') and (SR.Name <> '..') then
begin
Localizar(DIR + SR.Name, ARQ, LIST); //Reinicia a busca no subdiretório encontrado
Application.ProcessMessages; //Essa linha pode ser eliminada se executar a procedure numa outra thread
end;
end;
until FindNext(SR) <> 0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Localizar('C:\Usina_Comvap_ex', '*.dbf', ListBox1.Items);
end;

and after locating this file, I would like to transfer them to another folder as follows:

procedure TForm1.Button3Click(Sender: TObject);
var
Origem:string;
Destino:string;
i : Integer;
 begin
  for i := 0 to listbox1.items.Count-1 do
    begin
      Origem:=listbox1.items[1];
      Destino:='C:\Users\Guilherme\Desktop\shp\'+ExtractFileName(listbox1.items[i]);
      CopyFile(PChar(Origem), PChar(Destino), true);
    end;
 end;

Ok, it copies the files but when it tries to open it, it breaks the files:

    
asked by anonymous 02.08.2016 / 20:18

1 answer

-1

I got your code, and I added some Begins and Ends just to compile, and worked perfectly for xls files.

In your message, you are trying to open a .dbf extension file with Excel, and that's the problem. So much so that if you continue with this message, probably Excel itself will suggest some adaptations, and will be able to open the file perfectly.

PS: I tested your code with .dbf files as well.

    
02.08.2016 / 21:12