全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1861
推到 Plurk!
推到 Facebook!

搜索磁碟中特定檔案,並回傳資料夾

答題得分者是:Miles
stonys
初階會員


發表:64
回覆:111
積分:38
註冊:2002-09-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-10-06 14:08:44 IP:61.59.xxx.xxx 未訂閱
各位版上的大大 小弟這邊有個問題想請教大家一下 如果我想搜索磁碟中特定格式的檔案 即if exist 特定格式檔案 則回傳資料夾 那該如何實作比較好呢? 請指教
delphiwww
資深會員


發表:145
回覆:363
積分:368
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-10-07 09:08:11 IP:202.145.xxx.xxx 未訂閱
你可以看一下這篇文章,然後利用尋找 c: or d:應該就可以找到答案
引言: 各位版上的大大 小弟這邊有個問題想請教大家一下 如果我想搜索磁碟中特定格式的檔案 即if exist 特定格式檔案 則回傳資料夾 那該如何實作比較好呢? 請指教
Miles
尊榮會員


發表:27
回覆:662
積分:622
註冊:2002-07-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-10-07 10:09:35 IP:210.58.xxx.xxx 未訂閱
Hello 試試這一段吧    

procedure ShowFile(InDir, SubType: String);
var
  sr: TSearchRec;
  FileAttrs: Integer;
  Showed : boolean;
begin
  Showed := False;
  if FindFirst(InDir '\*.*', faAnyFile, sr) = 0 then begin
     while FindNext(sr) = 0 do begin
           if (sr.Name = '.') or (sr.Name = '..') then continue;
           if ((sr.Attr and faDirectory) = faDirectory) then
              ShowFile(InDir   '\'   sr.Name, SubType)
           else begin
              if LowerCase(ExtractFileExt(sr.Name)) = '.' LowerCase(SubType) then begin
                 if not Showed then
                    Memo1.Lines.Add( InDir   ' [DIR]');
                 Memo1.Lines.Add( '   ' sr.Name   ' [File]');
              end;
           end;
           Application.ProcessMessages;
     end;
  end;
  FindClose(sr);
end;    
procedure TForm1.Button1Click(Sender: TObject);
begin
   ShowAllFile('c:', 'Log')
end;
------


我不是高手, 高手是正在銀幕前微笑的人.
系統時間:2024-04-30 15:54:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!