[VB6] 怎樣可以取得本機上所有TXT檔案的完整路徑?

2007-06-08 8:51 pm
怎樣可以取得本機上所有TXT檔案的完整路徑?

假如檔案是這樣的:

C:
|-A.TXT
|-B.TXT
|-FOLDER1
 |-C.TXT
|-FOLDER2
 |-FOLDER3
  |-FILE.TXT
D:
|-DTXT.TXT

結果應是:

"C:\\A.TXT"
"C:\\B.TXT"
"C:\\FOLDER1\\C.TXT"
"C:\\FOLDER2\\FOLDER3\\FILE.TXT"
"D:\\DTXT.TXT"

請間該怎樣做?
更新1:

TO ALL : PLEASE USE CHINESE !

回答 (2)

2007-06-09 5:10 am
✔ 最佳答案
You may do it like this:


圖片參考:http://i206.photobucket.com/albums/bb265/a048042l/traverse.jpg


Depends on the number of files in your drives, it may takes several minutes to run.

Please click here to download the source code.

2007-06-09 16:07:39 補充:
感謝garlic2010為我作了補充,我不選擇“late binding”的做法,是因為要「優化」程式的執行速度,我現在用中文在此列出在VB 6加入「Microsoft Scripting Runtime參考」之步驟:1. 選「專案」→ 選「參考」加入至顯示「參考對話盒」2. 按「瀏覽」以開啟「加入參考對話盒」3. 選“scrrun . dll”檔案,按「確定」關閉「加入參考對話盒」(“Microsoft Scripting Runtime”在「參考對話盒」的「可用的參考」清單中列出) 4. 按「確定」關閉「參考對話盒」

2007-06-09 16:09:01 補充:
 請注意:因為程式要做大量讀取外部儲存裝置的操作,執行需時,請耐心等候。 
參考: 原創
2007-06-09 8:11 am
雁妮 gives a very neat program.

I have just one thing to add. To use FileSystemObject, you have to add
C:\Winsows\System32\Scrrun.dll to Project Reference or use late binding

Dim fs as Object

Set fs = CreateObject("Scripting.FileSystemObject")


收錄日期: 2021-04-25 20:33:17
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070608000051KK01276

檢視 Wayback Machine 備份