如何自動搜尋程式所在,磁碟或光碟機之特定檔案(*.MP3)? |
答題得分者是:Justmade
|
qoo1234
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
chih
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:48 回覆:1186 積分:639 註冊:2002-04-02 發送簡訊給我 |
|
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
何謂自動? 基楚搜尋方式:
procedure TForm1.Button1Click(Sender: TObject); var sr: TSearchRec; begin StringGrid1.RowCount := 1; if FindFirst(Path '*.mp3', 0, sr) = 0 then begin repeat Memo1.Lines.Add(sr.Name); until FindNext(sr) <> 0; FindClose(sr); end; end;Path 的找法 : 程式所在 : ExtractFileDir(application.ExeName) 磁碟 ,光碟機 : 用 GetLogicalDriveStrings 取得 Drive List (非必要) 用 GetDriveType 取得 DriveType : 0 The drive type cannot be determined. 1 The root directory does not exist. DRIVE_REMOVABLE The drive can be removed from the drive. DRIVE_FIXED The disk cannot be removed from the drive. DRIVE_REMOTE The drive is a remote (network) drive. DRIVE_CDROM The drive is a CD-ROM drive. DRIVE_RAMDISK The drive is a RAM disk. 確定了那個 Drive 是磁碟及光碟便可以此來作Path 找檔案了 當然你也可用元件 : 用 TFileListBox Directory 輸入 Path Mask 輸入 *.MP3 從 Items 讀檔名 發表人 - Justmade 於 2003/05/08 08:38:14 |
qoo1234
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
chih
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:48 回覆:1186 積分:639 註冊:2002-04-02 發送簡訊給我 |
function GetFileList(var lst: TListBox; const dir: string): integer; var sr: TSearchRec; begin lst.Items.Clear; if FindFirst(dir '*.mp3', faAnyFile, sr) = 0 then try repeat if (sr.Attr and faDirectory) = 0 then lst.Items.Add(sr.Name); until FindNext(sr) <> 0; finally FindClose(sr); end; Result := lst.Items.Count; end; procedure TForm1.Button1Click(Sender: TObject); begin GetFileList(ListBox1,''); end;TRY TRY SEE 引言: 何謂自動搜尋? 程式啟動後,自動將程式所在之磁碟位置或光碟機位置, 搜尋特定檔案(*.MP3),包含各個資料夾一併搜尋並放置 於ListBox元件上。 |
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
搜尋包括子目錄 :
procedure TForm1.Button1Click(Sender: TObject); begin AddFiles(ExtractFileDir(application.ExeName),'*.mp3'); AddFiles(OtherPath,'*.mp3); end; procedure AddFIles(path, Mask : string); var sr: TSearchRec; begin StringGrid1.RowCount := 1; if FindFirst(Path '*.mp3',0, sr) = 0 then begin repeat ListBox.Items.Add(Path sr.Name); until FindNext(sr) <> 0; FindClose(sr); end; if FindFirst(Path ,faDirectory, sr) = 0 then begin repeat if (sr.Attr and faDirectory) = faDirectory then AddFiles(Path sr.Name,Mask); // process sub-directory until FindNext(sr) <> 0; FindClose(sr); end; end;Other Path 可以是光盤/軟盤根目錄,可用我上面說的方法找出 修改 : 漏了 Mask 發表人 - Justmade 於 2003/05/08 11:16:08 |
qoo1234
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
引言:還差一步,自動搜尋各個資料夾特定檔案(*.MP3)~~995 to mefunction GetFileList(var lst: TListBox; const dir: string): integer; var sr: TSearchRec; begin lst.Items.Clear; if FindFirst(dir '*.mp3', faAnyFile, sr) = 0 then try repeat if (sr.Attr and faDirectory) = 0 then lst.Items.Add(sr.Name); until FindNext(sr) <> 0; finally FindClose(sr); end; Result := lst.Items.Count; end; procedure TForm1.Button1Click(Sender: TObject); begin GetFileList(ListBox1,''); end;TRY TRY SEE引言: 何謂自動搜尋? 程式啟動後,自動將程式所在之磁碟位置或光碟機位置, 搜尋特定檔案(*.MP3),包含各個資料夾一併搜尋並放置 於ListBox元件上。 |
qoo1234
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
引言: 搜尋包括子目錄 :還差一步,自動搜尋各個資料夾特定檔案(*.MP3)~~995 to meprocedure TForm1.Button1Click(Sender: TObject); begin AddFiles(ExtractFileDir(application.ExeName),'*.mp3'); AddFiles(OtherPath,'*.mp3); end; procedure AddFIles(path, Mask : string); var sr: TSearchRec; begin StringGrid1.RowCount := 1; //少了這一行,就會顯示完整路徑,太神奇了! if FindFirst(Path '*.mp3',0, sr) = 0 then begin repeat ListBox.Items.Add(Path sr.Name); until FindNext(sr) <> 0; FindClose(sr); end; if FindFirst(Path ,faDirectory, sr) = 0 then begin repeat if (sr.Attr and faDirectory) = faDirectory then AddFiles(Path sr.Name,Mask); // process sub-directory until FindNext(sr) <> 0; FindClose(sr); end; end;Other Path 可以是光盤/軟盤根目錄,可用我上面說的方法找出 修改 : 漏了 Mask 發表人 - Justmade 於 2003/05/08 11:16:08 |
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
引言: StringGrid1.RowCount := 1; //少了這一行,就會顯示完整路徑,太神奇了!????? StringGrid ??? 無端來個 StringGrid 做甚麼 ??? 顯示完整路徑是因為 ListBox.Items.Add(Path sr.Name); 因為檔案來自多個路徑,若不加上完整路徑之後要播放去那裡找?? 引言: 還差一步,自動搜尋各個資料夾特定檔案(*.MP3)~~995 to me |
qoo1234
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
引言: ????? StringGrid ??? 無端來個 StringGrid 做甚麼 ??? ...J sir 版大,謝謝指教! StringGrid1.RowCount := 1; 這一行在你的程式碼中,不知有何意義? |
qoo1234
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
引言:引言: ????? StringGrid ??? 無端來個 StringGrid 做甚麼 ??? ...J sir 版大,謝謝指教! StringGrid1.RowCount := 1; 這一行在你的程式碼中,不知有何意義? |
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |