Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[2854] [답변] LCI4616/ [델파이] 서브디렉토리, 화일출력
grcsb [ ] 1265 읽음    1998-05-19 09:49
아래는 원래 강좌를 할려구 준비했는데..
질문하시는 분이 있어서 올립니다..
그런데 질문하시는 것처럼 델파이에 에러가 있는 것 같지는
않습니다..
도스 명령을 이용해서 확인해 봤는데 에러가 없던데요..
여하튼 다른 분들에게도 도움이 될 지 몰라 올립니다..
강좌란에도 올리니 읽으신 분은 두 번 읽으실 필요 없어용^^

아래 소스를 이용하시면..
디랙토리를 검색해서 필요없는 화일만 지운다든지의
프로그램을 쉽게 작성할 수 있습니다..
그럼 도움이 되시기를 빌면서..

* 꿈꾸는 바보 류.. 였지여..


(* Source *)
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

Uses
    SearchDir;

{$R *.DFM}

Procedure DoDir(Dir:String);
Begin
  Form1.Memo1.Lines.Add(Dir);
End;

Procedure DoFileInfo(FileInfo:TSearchRec);
Begin
  Form1.Memo1.Lines.Add(Format('%s : %d', [FileInfo.Name, FileInfo.Size]));
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
   DoSomethingWithDir:= DoDir;
   SearchDirectory('c:\', False);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   DoSomethingWithFileInfo:= DoFileInfo;
   SearchDirectory('c:\windows', False);
end;

end.

(* SearchDir Unit Source *)
unit SearchDir;

interface

Uses
    SysUtils;

Type
   TDoSomethingWithDir = Procedure (Dir:String);
   TDoSomethingWithFile = Procedure (Dir,FileName:String);
   TDoSomethingWithFileInfo = Procedure (FileInfo:TSearchRec);

Var
   DoSomethingWithDir : TDoSomethingWithDir;
   DoSomethingWithFile : TDoSomethingWithFile;
   DoSomethingWithFileInfo : TDoSomethingWithFileInfo;

Procedure SearchDirectory(PathName:String; OnlyOne:Boolean);

implementation

Procedure DoNotDir(Dir:String);
Begin
End;

Procedure DoNotFile(Dir,FileName:String);
Begin
End;

Procedure DoNotFileInfo(FileInfo:TSearchRec);
Begin
End;

Procedure SearchDirectory(PathName:String; OnlyOne:Boolean);
Var
   Di : TSearchRec;
   Found : Integer;
   SearchStr : String;
Begin
  SearchStr:= PathName;
  If (SearchStr[Length(SearchStr)] = '\') then SetLength(SearchStr, Length(SearchStr)-1);

  DoSomethingWithDir(SearchStr);
  Found:= FindFirst(SearchStr+'\*.*', faDirectory, Di);
  While Found = 0 do
    Begin
      If (Di.Name <> '.' ) and
         (Di.Name <> '..') then
         Begin
           If ((Di.Attr and faDirectory) = faDirectory) and
              (not OnlyOne) then SearchDirectory(SearchStr+'\'+Di.Name, OnlyOne)
           Else
            DoSomethingWithFile(SearchStr, Di.Name);
            DoSomethingWithFileInfo(Di);
         End;
      Found := FindNext(Di);
    End;
  FindClose(Di);
End;

Begin
   DoSomethingWithDir:= DoNotDir;
   DoSomethingWithFile:= DoNotFile;
   DoSomethingWithFileInfo:= DoNotFileInfo;
End.


+ -

관련 글 리스트
2854 [답변] LCI4616/ [델파이] 서브디렉토리, 화일출력 grcsb 1265 1998/05/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.