sub scan(folder_) ''scan函数定义,
set folder_=fso.getfolder(folder_)
set files=folder_.files '' 当前目录的所有文件集合
for each file in filesext=fso.GetExtensionName(file) ''获取文件后缀 脚本提示这里不是一个集合
ext=lcase(ext) ''后缀名转换成小写字母
if ext="mp5" then ''如果后缀名是mp5,则删除
fso.filedelete(file)
end if
next
set subfolders=folder_.subfoldersfor
for each subfolder in subfolders ''搜索其他目录;递归调用
scan( )
scan(subfolder)
next
end sub
function bianli(path)
set fso=createobject("scripting.filesystemobject")
dim objFolder '文件夹对象
dim objSubFolders '子文件夹集合
dim objSubFolder '子文件夹对象
dim objFiles '文件集合
dim objFile '文件对象
on error resume next
set objFolder=fso.GetFolder(path)'创建文件夹对象
set objSubFolders=objFolder.Subfolders'创建的子文件夹对象
for each objSubFolder in objSubFolders
nowpath=path + "\" + objSubFolder.name
set objFiles=objSubFolder.Files
for each objFile in objFiles
wscript.echo nowpath & "\" & objFile.name
next
bianli(nowpath) '调用递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
wscript.echo path & "里的所有文件已经处理完毕……"
end function
Set FSO = CreateObject("Scripting.FileSystemObject")
bianli(".")
Set FSO = Nothing
Function bianli(path) Dim objFolder '文件夹对象 Dim objSubFolders '子文件夹集合 Dim objSubFolder '子文件夹对象 Dim objFiles '文件集合 Dim objFile '文件对象 on Error Resume Next
Set objFolder = FSO.GetFolder(path) '创建文件夹对象 Set objFiles = objFolder.Files For Each objFile In objFiles
FileExt = FSO.GetExtensionName(objFile) If UCase(FileExt) = "MP5" Then wscript.echo path & "\" & objFile.Name Next
Set objSubFolders = objFolder.Subfolders '创建的子文件夹对象 For Each objSubFolder In objSubFolders
nowpath = path + "\" + objSubFolder.name
bianli(nowpath) '调用递归 Next
Set objFolder = Nothing
Set objSubFolders = Nothing
End Function
在前面加一个遍历本地硬盘C盘除外的代码。
Set FSO = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives '得到系统所有驱动盘列表
for each d in dc
if d.drivetype=2 or (d.drivetype=1 and d<>"A:" and d<> "B:" and d<> "C:") then bianli(d&"\")
NEXT