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

想知道某个目录下*.jpg文件共有多少个怎么做?

答題得分者是:channel
coldcoffee
一般會員


發表:60
回覆:22
積分:16
註冊:2003-05-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-07 16:41:18 IP:202.106.xxx.xxx 未訂閱
想知道某个目录下*.jpg文件共有多少个怎么做? 而且我还想知道每个.jpg文件的文件名,怎么做? 请具体说明!谢谢!!!
Rain
資深會員


發表:31
回覆:236
積分:268
註冊:2003-02-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-07 17:05:51 IP:218.85.xxx.xxx 未訂閱
具體實現如下,試試看,如果還要包括目錄的子目錄下的檔,可再參考Justmade大大的代碼:http://delphi.ktop.com.tw/topic.php?TOPIC_ID=33251    
procedure TForm1.Button1Click(Sender: TObject);
var
  ADir: string;
  sr: TSearchRec;
  AFileCount: Integer;
begin
  ADir := 'D:\';
  AFileCount := 0;
  if FindFirst(ADir   '*.Jpg', 0, sr) = 0 then
  begin
    repeat
    begin
      ListBox1.Items.Add(ADir   sr.Name);//檔案名稱列表
      Inc(AFileCount);
    end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Label1.Caption := IntToStr(AFileCount);//文件數
end;
發表人 - Rain 於 2003/07/07 17:07:00
channel
尊榮會員


發表:67
回覆:707
積分:854
註冊:2002-05-02

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-07 17:06:54 IP:211.21.xxx.xxx 未訂閱
引言: 想知道某个目录下*.jpg文件共有多少个怎么做? 而且我还想知道每个.jpg文件的文件名,怎么做? 请具体说明!谢谢!!!
您可以使用TFileListBox(在Win3.1頁次) For Example:
procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  FileListBox1.Directory := '某個目錄的路徑';
  FileListBox1.Mask := '*.jip';
  //取得共有幾個JPG文件(FileListBox1.Items.Count)
  ShowMessage('共有:' IntToStr(FileListBox1.Items.Count) 'JPG文件');
  //取得每個JPG文件的文件名
  for I := 0 to FileListBox1.Items.Count - 1 do
    ShowMessage(FileListBox1.Items[I]);
end;
~小弟淺見,參考看看~
------
~小弟淺見,參考看看~
danny
版主


發表:100
回覆:522
積分:595
註冊:2002-03-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-07 17:09:05 IP:211.76.xxx.xxx 未訂閱
引言: 想知道某个目录下*.jpg文件共有多少个怎么做? 而且我还想知道每个.jpg文件的文件名,怎么做? 请具体说明!谢谢!!!
最簡單的方式是使用 FileListBox.Mask := '*.jpg;*.jpeg'; 然後用以下方式取出
for i := 0 to FileListBox.Items.Count-1 do
  JpgFileName := FileListBox.Items.Strings[i];
共有幾個 jpg 文件 FileCount := FileListBox.Items.Count; 發表人 - danny 於 2003/07/07 17:11:01
------
將問題盡快結案也是一種禮貌!
danny
版主


發表:100
回覆:522
積分:595
註冊:2002-03-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-07-07 18:21:11 IP:211.76.xxx.xxx 未訂閱
coldcoffee: 你跨多區發言違反版規, 請刪除多餘發言, 謝謝 !! http://delphi.ktop.com.tw/link.asp?TOPIC_ID=33593 http://delphi.ktop.com.tw/link.asp?TOPIC_ID=33595 http://delphi.ktop.com.tw/link.asp?TOPIC_ID=33594    請盡速處理, 不然要扣分 
------
將問題盡快結案也是一種禮貌!
hcker
中階會員


發表:95
回覆:118
積分:62
註冊:2003-02-09

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-07-08 07:37:37 IP:218.19.xxx.xxx 未訂閱
不知道這樣可以不 用listbox 搜索之後列出 *.jpg檔,從listbox 獲取 數目,同時已經得到這個檔案名,一目了然 ----------要知道自己有多笨,到DelphiK.Top來看看----------
wnhoo
高階會員


發表:75
回覆:443
積分:198
註冊:2003-04-22

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-07-08 15:29:18 IP:61.155.xxx.xxx 未訂閱
想知道某个目录下*.jpg文件共有多少个怎么做? 而且我还想知道每个.jpg文件的文件名,怎么做? 请具体说明!谢谢!!!    { 本程序所需控件 listbox1 label1 button1    }    unit Unit1;    interface    uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls;    type   TForm1 = class(TForm)     Button1: TButton;     ListBox1: TListBox;     Label1: TLabel;     procedure Button1Click(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end;    var   Form1: TForm1;    implementation    {$R *.dfm} { 函数 findfile返回找到的文件数目 dir     //待查询目录 filetype //查询文件类型 listbox1 //查询结果输出到listbox1中 } FUNCTION FindFile(Dir: String;FILETYPE:STRING;ListBox1:TLISTBOX):INTEGER; var   sr: TSearchRec;   FileAttrs: Integer; begin RESULT:=0;   FileAttrs := faAnyFile;   if FindFirst(Dir + '*.'+FILETYPE, FileAttrs, sr) = 0 then   begin     if (sr.Attr and FileAttrs) = sr.Attr then       ListBox1.Items.Add(Dir + sr.Name);     while FindNext(sr) = 0 do       if (sr.Attr and FileAttrs) = sr.Attr then         ListBox1.Items.Add(Dir + sr.Name);     FindClose(sr);     RESULT:=LISTBOX1.Count ;   end; end;    procedure TForm1.Button1Click(Sender: TObject); begin LABEL1.Caption :=INTTOSTR(FindFile('F:\','JPG',LISTBOX1)); end;    end.    风花雪月 e梦情缘
------
风花雪月 e梦情缘
系統時間:2024-04-28 6:44:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!