Post time: 2005年6月29日
因为原目录内有好多级子目录,每个目录下有一个index.xhtml的文件,现在要把所有文件更名为index.html,在网上找了好多批量改文件名的软件都只支持当前目录下,不支持子目录,所以干脆自己动手写了一个脚本,使用递归调用的方法,可以支持多级子目录内文件的更名
把以下内容复制到记事本并保存成 rename.vbs 即可,完整代码如下:
'--------代码开始------------------
Dim fso,cur_folder,sub_folders,sub_files
...
因为原目录内有好多级子目录,每个目录下有一个index.xhtml的文件,现在要把所有文件更名为index.html,在网上找了好多批量改文件名的软件都只支持当前目录下,不支持子目录,所以干脆自己动手写了一个脚本,使用递归调用的方法,可以支持多级子目录内文件的更名
把以下内容复制到记事本并保存成 rename.vbs 即可,完整代码如下:
'--------代码开始------------------
Dim fso,cur_folder,sub_folders,sub_files
Dim c_path
c_path="d:\temp\" '改名时的工作目录,文件都放这里
p=search_folder(c_path)
function search_folder(c_path)
'建立文件系统对象
Set fso=createobject("scripting.filesystemobject")
'将当前目录下的文件复制为另一个文件名
If fso.FileExists(c_path&"\index.xhtml") Then
fso.GetFile(c_path&"\index.xhtml").Copy c_path&"\index.html",true
fso.DeleteFile (c_path&"\index.xhtml")
End if
'建立建立当前目录对象
set cur_folder=fso.getfolder(c_path)
'建立当前目录的子目录对象集合
Set sub_folders=cur_folder.subfolders
'对子目录集合进行遍历
For each each_sub_folder in sub_folders
'确定子目录的属性为普通子目录
if each_sub_folder.attributes=16 then
sub_c_path=c_path&"\"&each_sub_folder.name
'递归检索当前子目录的下一级目录
p=search_folder(sub_c_path)
End If
Next
'清除所有对象
set each_sub_folder=nothing
set sub_folders=nothing
set cur_folder=nothing
set fso=nothing
End Function
MsgBox "完成"
'--------代码结束------------------
Tags: