線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2596
推到 Plurk!
推到 Facebook!

請教一下如何搜尋C:\下 的所有資料夾內的檔案

 
JS
一般會員


發表:22
回覆:26
積分:9
註冊:2002-07-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-08-12 09:54:58 IP:61.219.xxx.xxx 未訂閱
如題,我想搜尋C:下的所有資料夾內的所有檔案,不知有沒有方法,或是只有用SDK的FindFirstFile和FindNextFile來做呢?可否有example,因為我是一個delphi的新手!謝謝!
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-08-12 10:50:58 IP:61.219.xxx.xxx 未訂閱
我寫一個Dir Sub給您參考 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function Dirs(path:string;subdir:boolean;t:tstrings):boolean; var f:tSearchrec; dir:string; b:boolean; i:integer; begin dir:=extractfilepath(path); if copy(dir,length(dir),1)<>'\' then dir:=dir '\'; result:=false; if findfirst(path,$0000002f,f)=0 then begin repeat t.Add(dir f.Name); until findnext(f)<>0; FindClose(f); result:=true; end; if subdir then if findfirst(dir '*.*',$0000001F,f)=0 then begin repeat if (trim(f.name)<>'.') and (trim(f.name)<>'..') then Dirs(dir f.name '\' extractfilename(path),subdir,t); until findnext(f)<>0; FindClose(f); result:=true; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Dirs(edit1.text,true,memo1.lines); end; end. ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-08-22 00:47:20 IP:203.204.xxx.xxx 未訂閱
引言: 我寫一個Dir Sub給您參考 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function Dirs(path:string;subdir:boolean;t:tstrings):boolean; var f:tSearchrec; dir:string; b:boolean; i:integer; begin dir:=extractfilepath(path); if copy(dir,length(dir),1)<>'\' then dir:=dir '\'; result:=false; if findfirst(path,$0000002f,f)=0 then begin repeat t.Add(dir f.Name); until findnext(f)<>0; FindClose(f); result:=true; end; if subdir then if findfirst(dir '*.*',$0000001F,f)=0 then begin repeat if (trim(f.name)<>'.') and (trim(f.name)<>'..') then Dirs(dir f.name '\' extractfilename(path),subdir,t); until findnext(f)<>0; FindClose(f); result:=true; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Dirs(edit1.text,true,memo1.lines); end; end. ~~~Delphi K.Top討論區站長~~~
順便提醒 在 D5 以下 FindFirst 與 FindNext 是不會幫你比對檔案屬性的 即使屬性不對 , 只要名稱符合都會列出 , 所以屬性要靠你自己來寫程式比對 而 D6 有改正否 , 我就不知道了
系統時間:2024-04-25 9:40:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!