아래는 원래 강좌를 할려구 준비했는데..
질문하시는 분이 있어서 올립니다..
그런데 질문하시는 것처럼 델파이에 에러가 있는 것 같지는
않습니다..
도스 명령을 이용해서 확인해 봤는데 에러가 없던데요..
여하튼 다른 분들에게도 도움이 될 지 몰라 올립니다..
강좌란에도 올리니 읽으신 분은 두 번 읽으실 필요 없어용^^
아래 소스를 이용하시면..
디랙토리를 검색해서 필요없는 화일만 지운다든지의
프로그램을 쉽게 작성할 수 있습니다..
그럼 도움이 되시기를 빌면서..
* 꿈꾸는 바보 류.. 였지여..
(* 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.
|