파일 찾기
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ListFiles(D,Name,SearchName : String);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ListFiles(D, Name, SearchName: String);
var
SR: TSearchRec;
begin
if D[Length(D)] <> '' then
D := D + '';
if FindFirst(D+Name, faAnyFile, SR) = 0 then
repeat
if (SR.Attr <> faDirectory) and (SR.Name[1] <> '.') then
if AnsiUpperCase(SR.Name) = AnsiUpperCase(SearchName) then
ListBox1.Items.Add(D+SR.Name); {파일을 찾으면 label1.Caption에 디렉토리를 표시}
Until (FindNext(SR)<>0);
FindClose(SR);
if FindFirst(D+'*.*', faDirectory, SR) = 0 then
begin
repeat
if ((Sr.Attr and faDirectory) = faDirectory) and
(SR.Name[1]<>'.')
then
ListFiles(D+SR.Name+'', Name, SearchName); // 재귀적 호출을 한다
until (FindNext(SR) <> 0);
end;
FindClose(SR);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// c: 부터 하위 디렉토리에서 delphi32.exe 파일을 찾는다
ListFiles('c:','*.*','project1.exe');
end;
end.