Ver Mensaje Individual
  #5  
Antiguo 22-07-2014
darkamerico darkamerico is offline
Miembro
 
Registrado: dic 2010
Posts: 227
Reputación: 14
darkamerico Va por buen camino
Question Saludos

Gracias a todos aquellos amigos que respondieron, he probado cada código, ciertamente resuelven parte del problema, sin embargo, el problema en ellos es que buscan "mascaras", de la forma: *.pas, Arch.*, etc. por eso si existe un archivo llamado por ejemplo: INS_PHOTOSHOP_CC_14.EXE, no podre ubicarlo ingresando la palabra PHOTOSHOP, porque el archivo no comienza con dicha palabra.

El código que presento a continuación es la versión de Neftalí, pero presenta esta limitación:

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FindFile, StdCtrls;

type
  TForm1 = class(TForm)
    Buscar: TButton;
    lstArchivos: TListBox;
    Label1: TLabel;
    txtBuscar: TEdit;
    procedure BuscarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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;
  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);
      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;

procedure TForm1.BuscarClick(Sender: TObject);
var
  res:TStringList;
  i:integer;
begin
  res:=TStringList.Create;
  FindFiles('.',txtBuscar.Text+'*.*',true,res);
  for i := 0 to res.Count - 1 do
      lstArchivos.Items.Add(res[i]);
end;

end.

Saludos
Responder Con Cita