Ver Mensaje Individual
  #2  
Antiguo 18-11-2010
Avatar de javier_ecf
javier_ecf javier_ecf is offline
Miembro
 
Registrado: sep 2010
Posts: 32
Reputación: 0
javier_ecf Va por buen camino
Código Delphi [-]
procedure FindFiles(StartDir, FileMask: string; recursively: boolean; var FilesList: TStringList);
  const
    MASK_ALL_FILES = '*.*';
    CHAR_POINT = '.';
  var
    SR: TSearchRec;
    DirList: TStringList;
    IsFound: Boolean;
    i: integer;
    //cont:Integer;
  begin
    if (StartDir[length(StartDir)] <> '\') then begin
      StartDir := StartDir + '\';
    end;

    // Crear la lista de ficheos en el directorio StartDir (no directorios!)
    IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, SR) = 0;
    // MIentras encuentre
    while IsFound do  begin
      FilesList.Add(StartDir + SR.Name);
      //FilesList.Add(SR.Name);
      IsFound := FindNext(SR) = 0;
      //cont:=cont+1;
    end;
    FindClose(SR);

    // Recursivo?
    if (recursively) then begin
      // Build a list of subdirectories
      DirList := TStringList.Create;
      // proteccion
      try
        IsFound := FindFirst(StartDir + MASK_ALL_FILES, faAnyFile, SR) = 0;
        while IsFound do
        begin
          if ((SR.Attr and faDirectory) <> 0) and
            (SR.Name[1] <> CHAR_POINT) then
            DirList.Add(StartDir + SR.Name);
            IsFound := FindNext(SR) = 0;
        end;
        FindClose(SR);

        // Scan the list of subdirectories
        for i := 0 to DirList.Count - 1 do
          FindFiles(DirList[i], FileMask, recursively, FilesList);
      finally
       // DirList.Free;
      end;
    end;
  end;

{LISTA Y BORRADO}
Código Delphi [-]
procedure BorrarLogs;
var Lista:TStringList;
var i:integer;
begin
  Lista:=TStringList.Create;
  FindFiles('C:','*.log',true,Lista);

  for i:=0 to Lista.Count -1 do begin
      DeleteFile(PChar(Lista.Strings[i]));
  end;
  Lista.Free;
end;

No lo probe pero creo que funciona.

Última edición por rgstuamigo fecha: 19-11-2010 a las 23:55:06.
Responder Con Cita