Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Renombrar, eliminar ficheros con Delphi???? (https://www.clubdelphi.com/foros/showthread.php?t=6275)

mguixot 29-12-2003 13:00:05

Renombrar, eliminar ficheros con Delphi????
 
Hola gente,
estoy intentando realizar un pequeño módulo que me elimine unos determinados ficheros (una extensión concreta) de un directorio. Tambien necesitaria renombrar un fichero con un nombre concreto. Todo ello debo implementarlo desde una aplicacion Delphi, pero ahora mismo no se como realizarlo. Conoceis de algunos ejemplos interesantes?.

Saludos y felices Fiestas.

Miguel

Descendents 29-12-2003 13:10:44

Código:

procedure TForm1.BuscaFicheros(path, mask : AnsiString; var Value : TStringList; brec : Boolean);
 var
  srRes : TSearchRec;
  iFound : Integer;
 begin
  if ( brec ) then
    begin
    if path[Length(path)] <> '\' then path := path +'\';
    iFound := FindFirst( path + '*.*', faAnyfile, srRes );
    while iFound = 0 do
      begin
      if ( srRes.Name <> '.' ) and ( srRes.Name <> '..' ) then
        if srRes.Attr and faDirectory > 0 then
          BuscaFicheros( path + srRes.Name, mask, Value, brec );
      iFound := FindNext(srRes);
      end;
    FindClose(srRes);
    end;
  if path[Length(path)] <> '\' then path := path +'\';
  iFound := FindFirst(path+mask, faAnyFile-faDirectory, srRes);
  while iFound = 0 do
    begin
    if ( srRes.Name <> '.' ) and ( srRes.Name <> '..' ) and ( srRes.Name <> '' ) then
      Value.Add(path+srRes.Name);
    iFound := FindNext(srRes);
    end;
  FindClose( srRes );
 end;


lo llamas asi

Código:

procedure TForm1.Button1Click(Sender: TObject);
 var
    Ficheros:TStringList;
 begin
  Ficheros:=TStringList.Create;
  BuscaFicheros('c:\delphi3\','*.*',Ficheros,TRUE);
  Memo1.Lines.Assign(Ficheros);
  Ficheros.Free;
 end;

Esta sacado del trucomania

Con este procedimiento los localizas, y los eliminas o lo que quieras

Saludos

mguixot 29-12-2003 14:41:36

Muchas gracias, tio.
Ya he conseguido implementarlo. Tu ejemplo me ha servido de bastante ayuda.
Saludos y felices fiestas.


La franja horaria es GMT +2. Ahora son las 12:32:52.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi