vbs获取目录下的文件和文件夹集合

Dim sFolder, sExt, message
sFolder = "F:\Programming\Applications\VBScript"

Dim fs, oFolder, oFiles, oSubFolders
set fs = CreateObject("Scripting.FileSystemObject")
set oFolder = fs.GetFolder(sFolder)     '获取文件夹
set oSubFolders = oFolder.SubFolders    '获取子目录集合

for each folder in oSubFolders
    message = "文件夹:" & folder
    MsgBox message
Next

set oFiles = oFolder.Files              '获取文件集合
for each file in oFiles
    sExt = fs.GetExtensionName(file)    '获取文件扩展名
    sExt = LCase(sExt)                  '转换成小写
    message = "文件名:" & file.Name & ", 扩展名:" & sExt  '获得文件名(含扩展名,不含路径)和扩展名
    MsgBox message
Next

补充,上面的folder.Name可以得到文件夹的名称(不含路径)

如:folder = F:\Programming\Applications\VBScript\dd

通过folder.Name可以得到"dd"
 

转载于:https://www.cnblogs.com/joeblackzqq/archive/2011/02/27/1966288.html

你可能感兴趣的:(vbs获取目录下的文件和文件夹集合)