Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-11-2010
mefixxto mefixxto is offline
Miembro
 
Registrado: may 2008
Posts: 46
Poder: 0
mefixxto Va por buen camino
Question Buscar archivos .log y eliminarlos

Necesito de algun codigo que haga que mi aplicacion busque en el disco todos los archivos .log y eliminarlos..

gracias
Responder Con Cita
  #2  
Antiguo 18-11-2010
Avatar de javier_ecf
javier_ecf javier_ecf is offline
Miembro
 
Registrado: sep 2010
Posts: 32
Poder: 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
  #3  
Antiguo 19-11-2010
mefixxto mefixxto is offline
Miembro
 
Registrado: may 2008
Posts: 46
Poder: 0
mefixxto Va por buen camino
Muchisimas gracias, la verdad estaba probando otros metodos pero ya quedaba muy complicado
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Buscar Contenidos en Archivos FENIXadr API de Windows 2 15-06-2010 01:51:10
Buscar archivos.. pabloa_m OOP 19 05-12-2006 20:38:56
Buscar archivos jpg en carpetas y subcarpetas!! JuanErasmo API de Windows 4 23-11-2006 17:41:49
Buscar contenidos de archivos en windows XP josem Varios 3 06-05-2005 23:55:09
Buscar archivos con FindFirst eulogi_SCG Varios 2 28-09-2004 15:27:38


La franja horaria es GMT +2. Ahora son las 07:56:22.


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
Copyright 1996-2007 Club Delphi