Advertisement
hosttimer

PROCURAR ARQUIVO HD DELPHI

Oct 30th, 2016
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.36 KB | None | 0 0
  1.  
  2. unit uMain;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  8.   StdCtrls;
  9.  
  10. type
  11.   TfrMain = class(TForm)
  12.     CheckBox1: TCheckBox;
  13.     ListBox1: TListBox;
  14.     Edit1: TEdit;
  15.     Button1: TButton;
  16.     Edit2: TEdit;
  17.     Label1: TLabel;
  18.     Label2: TLabel;
  19.     lblNumberFound: TLabel;
  20.     procedure Button1Click(Sender: TObject);
  21.     procedure ListBox1DblClick(Sender: TObject);
  22.   private
  23.     procedure FileSearch(const PathName, FileName : string; const InDir : boolean);
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   frMain: TfrMain;
  30.  
  31. implementation
  32. {$R *.DFM}
  33. uses uFileInfo;
  34.  
  35.  
  36. procedure TfrMain.FileSearch(const PathName, FileName : string; const InDir : boolean);
  37. var Rec  : TSearchRec;
  38.     Path : string;
  39. begin
  40. Path := IncludeTrailingBackslash(PathName);
  41. if FindFirst(Path + FileName, faAnyFile - faDirectory, Rec) = 0 then
  42.  try
  43.    repeat
  44.      ListBox1.Items.Add(Path + Rec.Name);
  45.    until FindNext(Rec) <> 0;
  46.  finally
  47.    FindClose(Rec);
  48.  end;
  49.  
  50. If not InDir then Exit;
  51.  
  52. if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
  53.  try
  54.    repeat
  55.     if ((Rec.Attr and faDirectory) <> 0)  and (Rec.Name<>'.') and (Rec.Name<>'..') then
  56.      FileSearch(Path + Rec.Name, FileName, True);
  57.    until FindNext(Rec) <> 0;
  58.  finally
  59.    FindClose(Rec);
  60.  end;
  61. end; //procedimento
  62.  
  63. procedure TfrMain.Button1Click(Sender: TObject);
  64. begin
  65.   ListBox1.Clear;
  66.   lblNumberFound.Caption:=Inttostr(ListBox1.Items.Count) + ' arquivos encontrados. ';
  67.   FileSearch(Edit1.Text, Edit2.Text, CheckBox1.State in [cbChecked]);
  68.   lblNumberFound.Caption:=Inttostr(ListBox1.Items.Count) + ' arquivos encontrados. ';
  69. end;
  70.  
  71. procedure TfrMain.ListBox1DblClick(Sender: TObject);
  72. var SelectedFile : string;
  73.     Rec          : TSearchRec;
  74.     frInfo       : TfrFileInfo;
  75. begin
  76. SelectedFile := ListBox1.Items.Strings[ListBox1.ItemIndex];
  77. if FindFirst(SelectedFile, faAnyFile, Rec) = 0 then
  78.  begin
  79.   frInfo := TfrFileInfo.Create(Self);
  80.   try
  81.     frInfo.lblFile.Caption := SelectedFile;
  82.     frInfo.lblname.Caption := Rec.name;
  83.     frInfo.lblSize.Caption := Format('%d bytes',[Rec.Size]);
  84.     frInfo.lblModified.Caption := DateToStr(FileDateToDateTime(Rec.Time));
  85.     frInfo.lblShortName.Caption := Rec.FindData.cAlternateFileName;
  86.     frInfo.ShowModal;
  87.   finally
  88.     frInfo.Free;
  89.   end;
  90.   FindClose(Rec)
  91.  end;
  92. end;
  93.  
  94. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement