Ver Mensaje Individual
  #6  
Antiguo 29-02-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Cita:
Empezado por Paulao Ver Mensaje
ecfisa, hizo algunas alteraciones y ahora estas. Una pregunta: Como hago para hacer busqueda en .pas y .dfm al mismo tiempo con FindFirst?
No se puede hacer con FindFirst en una sola llamada, sin embargo se me ocurre un truco usando TStrings. Podría implementarse de forma recursiva´pero consume más recursos y quizá sea un poco más lento.
Código Delphi [-]
function TextFoundInFile(Ruta: string; const FileMask:string;  const Buscado: string): TStrings;
var
  SR: TSearchRec;
  txt: TextFile;
  Row: string;
  Found: Boolean;
  NroExt: TStrings;
  i: Integer;
begin
  NroExt:= TStringList.Create;
  try
    NroExt.Delimiter:= ';';
    NroExt.DelimitedText:= FileMask;
    Ruta:= IncludeTrailingPathDelimiter(Ruta);
    Result:= TStringList.Create;
    for i:= 0 to NroExt.Count - 1 do
    begin
      if FindFirst(Ruta + NroExt[i], faAnyFile - faDirectory, SR) = 0 then
        repeat
          AssignFile(txt,Ruta + SR.Name);
          Reset(txt);
          Found:= False;
          while not Eof(txt) and not Found do
          begin
            Readln(txt, Row);
            if Pos(Buscado, Row) > 0 then
            begin
              Result.Add(Ruta + SR.Name);
              Found:= True
            end
          end;
          CloseFile(txt);
        until FindNext(SR) <> 0
    end
  finally
    NroExt.Free
  end
end;

Llamada:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
 edFileMask.Text:= '*.PAS; *.DFM';  // El separador TIENE que  ser ';'
 ListBox1.Items:= TextFoundInFile(edRuta.Text, edFileMask.Text, edBuscado.Text).SaveToFile('C:\LISTA.TXT')
end;
De ese modo podés pasar la máscara que desees al argumento FileMask, por ejemplo: '*.PAS;*.DFM;*.TXT;*.BAT;*.RC'

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 29-02-2012 a las 17:05:20.
Responder Con Cita