Ver Mensaje Individual
  #2  
Antiguo 01-02-2011
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - Espańa
Posts: 18.297
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
A mi me funciona algo como esto (además puedes hacerlo recursivo):

Código Delphi [-]
var
  TS:TStringList;
  i:Integer;
begin

  try
    TS := TStringList.Create();
    FindFiles('c:\windows\temp', '*.*', True, TS);
    for i := 0 to (TS.Count - 1) do begin
      DeleteFile(TS[i]);
    end;
  finally
    FreeAndNil(TS);
  end;

La función FindFiles se puede encontrar en la sección de trucos del club.

Código Delphi [-]
procedure FindFiles(StartDir, FileMask: string; recursively: boolean; var FilesList: TStringList);
var
  SR: TSearchRec;
  DirList: TStringList;
  IsFound: Boolean;
  i: integer;
const
  CHAR_BACKSLASH = '\';
  MASK_ALL_FILES = '*.*';
  CHAR_POINT = '.';
begin
  if (StartDir[length(StartDir)] <> CHAR_BACKSLASH) then begin
    StartDir := StartDir + CHAR_BACKSLASH;
  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);
    IsFound := FindNext(SR) = 0;
  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;
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita