dim FileName,fs,foldername
foldername = InputBox("請輸入想要在哪個文件夾查找", "VBS查找文件")
If foldername = "" Then
wscript.quit
End If
Set fs = CreateObject("scripting.filesystemobject")
digui (foldername)'調(diào)用遞歸函數(shù)進(jìn)行查找
msgbox FileName '結(jié)果顯示
'下面是遞歸查找函數(shù)
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) '獲取文件擴(kuò)展名
sExt = LCase(sExt) '轉(zhuǎn)換成小寫
message = "文件名:" file.Name ", 擴(kuò)展名:" sExt '獲得文件名(含擴(kuò)展名,不含路徑)和擴(kuò)展名
MsgBox message
Next