VBS如何批量修改文件扩展名

最近一直在学习VBS语言,求vbs代码能修改路径下所有的某一类型文件的扩展名,包括子级目录下的, 比如JPG类型~~
有些不不懂,能解释下不,谢谢
1,这段是什么意思呢
If fso.GetExtensionName(i)=ext Then
ReDim Preserve paths(c)
paths(c)=i
c=c+1
End If

2。这句t=searchext(i,ext,searchall)为什么可以在自定义函数里面使用呢。

谢谢那位朋友,楼批处理我已经会了,就是想知道VBS是怎么处理的

Function searchext(folder,ext,searchall)
'folder是要进行检索的文件夹路径
'ext是要查找的一类文件的扩展名
'searchall是true时会进入子文件夹进行查找
Set fso=CreateObject("scripting.filesystemobject")
Set f=fso.GetFolder(folder)
Dim paths()
For Each i In f.Files
If fso.GetExtensionName(i)=ext Then
ReDim Preserve paths(c)
paths(c)=i
c=c+1
End If
Next
If searchall=True Then
For Each i In f.SubFolders
t=searchext(i,ext,searchall)
For Each j In t
ReDim Preserve paths(c)
paths(c)=j
c=c+1
Next
Next
End If
searchext=paths
End Function

main

Sub main()
Set fso=CreateObject("scripting.filesystemobject")
old=InputBox("请输入原来的扩展名(如“exe”):")
Ne=InputBox("请输入要改成的扩展名(如“jpg”):")
For Each i In WScript.Arguments
t=searchext(i,old,True)
For Each j In t
Set f=fso.GetFile(j)
f.Name=fso.GetBaseName(j)&"."&ne
Set f=nothing
Next
Next
End Sub

直接将你的要改扩展名的文件所在的文件夹拖放到这个VBS文件上就OK了,可以拖放任意多个文件夹,子目录中的文件也会被一并处理
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-01-01
If WScript.Arguments.Count=0 Then WScript.Quit
Dim path,wShell,cmd
path=WScript.Arguments(0)
cmd="cmd.exe /c for /f "&Chr(34)&"tokens=1"&Chr(34)&" %1 in ('dir "&path&"\*.jpg /s /b')do ren %1 %~n1.txt"
Set wShell=CreateObject("Wscript.Shell")
wShell.Run cmd,True
WScript.Echo "done"本回答被提问者采纳
第2个回答  2011-01-01
1、
Dim paths() '定义一个数组
If fso.GetExtensionName(i)=ext Then '判断文件扩展名是不是要改的
ReDim Preserve paths(c) '如果是重新定义数组界标
paths(c)=i'把文件名保存到数组中
c=c+1'界标加1 用于下一次进入时重新定义新的界标
End If

2、
t=searchext(i,ext,searchall)
用递归的方式搜索子目录
相似回答