Corrupted file while copying from one folder to another

Asked

Viewed 144 times

1

I am 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 that 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 while trying to open it comrrompes the files:

inserir a descrição da imagem aqui

1 answer

-1

I took 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 an extension file .dbf by Excel, and that’s the problem. So much so that if you proceed with this message, probably Excel itself will suggest some adaptations, and you will be able to open the file perfectly.

PS.: I tested your code with files .dbf also.

  • disagree, on the source path, I can open . dbf correctly,

  • @Guilhermelima, with Excel ?

  • yes, or liboffice

  • You can share the file ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.