VBS获取指定文件夹内所有文件列表
VBS获取指定文件夹根目录所有文件和根目录所有文件夹列表(多级的文件夹不要),并循环输出。
[解决办法]
str = "e:\script\vbs"ListFolder1 strListFolder2 strListFolder3 strSub 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 SubSub 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 SubSub 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 strOutEnd Sub