'遍历处理path及其子目录所有文件
Sub ShowAllFile(Path)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set f = FSO.GetFolder(Path)
Set fc2 = f.files
For Each myfile in fc2
WScript.Echo path&"\"&myfile.name
Next
Set fc = f.SubFolders
For Each f1 in fc
ShowAllFile path&"\"&f1.name
Next
Set FSO = Nothing
End Sub
遍历所有folder_中的txt文件
'根目录
Set fso=createobject("scripting.filesystemobject")
set folder_=fso.getfolder(folder_)
set files=folder_.files
for each file in files
ext=mid(file,InStrRev(file, ".")+1)
ext=lcase(ext)
if ext="txt" then
MsgBox(file)
end if
next
'根目录+子目录
sub scan(folder_)
Set fso=createobject("scripting.filesystemobject")
set folder_=fso.getfolder(folder_)
set files=folder_.files
for each file in files
ext=mid(file,InStrRev(file, ".")+1)
ext=lcase(ext)
if ext="txt" then
all_file=all_file+file+" "
end if
next
set subfolders=folder_.subfolders
for each subfolder in subfolders
scan(subfolder)
next
end sub
all_file=""
scan("E:\shi")
WScript.Echo all_file