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作者: slore 时间: 2008-2-1 12:06 注释是单引号……
for each file in filesext=fso.GetExtensionName(file)
貌似要写2句吧?作者: Vampire 时间: 2008-2-1 14:48 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作者: hackhd 时间: 2008-2-1 20:01 查找扩展名为mp5的那几句呢?作者: slore 时间: 2008-2-1 22:27 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作者: hackhd 时间: 2008-2-1 22:43 这段程序就是运行起来如果检测到扩展名为MP5就弹窗显示出路径是吧。
怎么这样调用的呢bianli(".") 有点不明白。
[ Last edited by hackhd on 2008-2-1 at 10:47 PM ]作者: slore 时间: 2008-2-1 22:56 . 表示当前目录……作者: hackhd 时间: 2008-2-1 23:02 你自己测试过没?我在当前目录建一个XX.MP5脚本也不提示啊。作者: slore 时间: 2008-2-1 23:22 我测试过的……
那就不知道了。。。作者: hackhd 时间: 2008-2-5 21:02 在前面加一个遍历本地硬盘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
For Each objFile In objFiles'脚本提示这句没有权限作者: slore 时间: 2008-2-5 22:06 这个有人提过……遍历的时候访问某些文件夹过不了。。。
但是直接用函数bianli(那个目录)确可以。