回覆列表
  • 1 # 漏光是想想而已

    "這個函式用來查詢指定目錄下,指定型別檔案的路徑Function SearchFiles(Path As String, FileType As String)Dim Files() As String "檔案路徑Dim Folder() As String "資料夾路徑Dim a, b, c As LongDim sPath As StringsPath = Dir(Path & FileType) "查詢第一個檔案Do While Len(sPath) "迴圈到沒有檔案為止 a = a + 1 ReDim Preserve Files(1 To a) Files(a) = Path & sPath "將檔案目錄和檔名組合,並存放到陣列中 List1.AddItem Files(a) "加入list控制元件中 sPath = Dir "查詢下一個檔案 DoEvents "讓出控制權LoopsPath = Dir(Path & "\", vbDirectory) "查詢第一個資料夾Do While Len(sPath) "迴圈到沒有資料夾為止 If Left(sPath, 1) "." Then "為了防止重複查詢 If GetAttr(Path & "\" & sPath) And vbDirectory Then "如果是資料夾則。。。。。。 b = b + 1 ReDim Preserve Folder(1 To b) Folder(b) = Path & sPath & "\" "將目錄和資料夾名稱組合形成新的目錄,並存放到陣列中 End If End If sPath = Dir "查詢下一個資料夾 DoEvents "讓出控制權LoopFor c = 1 To b "使用遞迴方法,遍歷所有目錄 SearchFiles Folder(c), FileTypeNextEnd FunctionPrivate Sub Command1_Click() "呼叫SearchFiles "e:\", "*.exe"End Sub

  • 中秋節和大豐收的關聯?
  • 加溼器清洗後,噴不出霧,是啥回事了?