|
还有比cmd dir更快的?学习一下
- Public Function 遍历文件(aPath$, aExtensionName$)
- Dim ws, aNum%, arr
- Set ws = CreateObject("WScript.Shell") 'Shell对象wshom.ocx,用于后台执行cmd命令
- If Right(aPath, 1) <> "" Then aPath = aPath & ""
- ws.Run Environ$("comspec") & " /c dir " & Chr(34) & aPath & aExtensionName & Chr(34) & " /s /b /a:-d > C:\tmpDoc.txt", 0, True '遍历获取Word文件,并列表到临时文件,同步方式
- aNum = FreeFile() '空闲文件号
- Open "C:\tmpDoc.txt" For Input As #aNum
- arr = Split(StrConv(InputB(LOF(aNum), aNum), vbUnicode), vbCrLf) '将遍历结果从文件读取到数组中
- Close #aNum
- ws.Run Environ$("comspec") & " /c del /q /s " & Chr(34) & "C:\tmpDoc.txt" & Chr(34), 0, False '删除临时文件,异步方式
- arr = Filter(arr, "$", False) '不包含$,即非word临时文件
- ReDim Preserve arr(0 To UBound(arr) - 1)
- 遍历文件 = arr
- End Function
复制代码 |
|