유돌이

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

2008. 12. 24. 18:04 델파이

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.

 

 

출처 : http://www.howto.pe.kr/


'델파이' 카테고리의 다른 글

OleVariant 형을 스트링으로 변환하는 방법  (0) 2008.12.29
쿠키 읽고/쓰기(GetCookie, SetCookie)  (0) 2008.12.29
실행파일 삭제  (0) 2008.12.24
키보드 이벤트[keybd_event  (0) 2008.12.24
레지스트리 값 읽고 쓰기  (0) 2008.12.24
posted by 유돌이