VBS 獲取指定文件夾根目錄所有文件和根目錄所有文件夾列表(多級的文件夾不要),并循環(huán)輸出,。
------解決方案--------------------
VBScript codestr = "e:\script\vbs"
ListFolder1 str
ListFolder2 str
ListFolder3 str
Sub ListFolder1(strFolder)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strFolder)
strOut = strOut & "文件夾:" & vbCrLf
For Each x In oFolder.SubFolders
strOut = strOut & x.Name & vbCrLf
Next
strOut = strOut & "文件:" & vbCrLf
For Each x In oFolder.Files
strOut = strOut & x.Name & vbCrLf
Next
WScript.Echo strOut
End Sub
Sub ListFolder2(strFolder)
'不能處理隱藏文件
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(strFolder)
For Each x In oFolder.Items
strOut = strOut & x.Type & vbTab & x.Path & vbCrLf
Next
WScript.Echo strOut
End Sub
Sub ListFolder3(strFolder)
Set oWMI = GetObject("Winmgmts:")
For Each x In oWMI.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='"& strFolder &"'}" & "where ResultClass = CIM_logicalfile")
strOut = strOut & x.Name & vbCrLf
Next
WScript.Echo strOut
End Sub
|