|
楼主 |
发表于 2015-2-6 13:54
|
显示全部楼层
win2009 发表于 2015-2-6 12:33
把Wscript.Echo
替换为 Msgbox 即可
你贴出来的那部分代码逻辑混乱,参数引用错误……无论如何,也是不能正常使用的。
我给重新整理了一下:- Sub ListFilesWMI()
- Set myFolder = CreateObject("Shell.Application").BrowseForFolder(0, "GetFolder", 0)
- If Not myFolder Is Nothing Then myPath = myFolder.Items.Item.Path Else MsgBox "Folder not Selected": Exit Sub
-
- [a:a] = "": [a1] = "Folder: " & myPath
- tms = Timer: Call GetSubFolders(myPath)
- MsgBox Format(Timer - tms, "0.000s")
- End Sub
- Sub GetSubFolders(strFolderName)
- Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
-
- strPath = Mid(Replace(strFolderName, "", "\") & "\", 3)
- Set colFiles = objWMIService.ExecQuery _
- ("Select * from CIM_DataFile where Path = '" & strPath & "'")
- For Each objFile In colFiles
- [a65536].End(3).Offset(1) = " Files: " & objFile.Name
- Next
-
- Set colSubfolders = objWMIService.ExecQuery _
- ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
- & "Where AssocClass = Win32_Subdirectory " _
- & "ResultRole = PartComponent")
- For Each objFolder In colSubfolders
- [a65536].End(3).Offset(1) = "Folder: " & objFolder.Name
- Call GetSubFolders(objFolder.Name)
- Next
- End Sub
复制代码 |
|