dim FileName,fs,foldername
foldername = InputBox("请输入想要在哪个文件夹查找", "VBS查找文件")
If foldername = "" Then
wscript.quit
End If
Set fs = CreateObject("scripting.filesystemobject")
digui (foldername)'调用递归函数进行查找
msgbox FileName '结果显示
'下面是递归查找函数
Function digui(path)
Set folder = fs.getfolder(path)
Set subfolders = folder.subfolders
Set Files = folder.Files
For Each i In Files
FileName=FileName i.path vbNewLine '找到则追加到变量FileName中
Next
For Each j In subfolders
digui (j.path) '递归查找子目录
Next
End Function
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