'**********************************************************
'多格式分类批量重命名脚本
'将同一类文件用1,2,3...的方式重命名
'Date : 2012-07-10
'Author : 乱码
'**********************************************************
ExtName = Array("jpg","gif","txt","rar") '要处理的后缀
Set fso = CreateObject("Scripting.FileSystemObject")
For i = 0 To UBound(ExtName) '分开处理不同的后缀
iCount = 1 '重命名计数
For Each x In fso.GetFolder(".").Files '遍历本目录所有文件
If LCase(fso.GetExtensionName(x.Name)) = LCase(ExtName(i)) Then
newName = iCount & "." & ExtName(i) '新的文件名
While fso.FileExists(newName) And LCase(newName) <> LCase(x.Name)
'检查新的文件名是否存在,或者是否是自己。
iCount = iCount + 1 '存在的话,编号+1
newName = iCount & "." & ExtName(i) '重新生成新的文件名
Wend
If LCase(newName) <> LCase(x.Name) Then x.Name = newName
'如果新文件名不等于自己,就重命名。
End If
Next
Next
Folder = "公司文件"
Name = "a.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set re = New RegExp
re.Pattern = "\d+" '正则表达式,取源文件名的数字,为了保持编号数序、
newBats = Split(vbCrLf & fso.OpenTextFile(Name).ReadAll,vbCrLf) '新的文件名数组
On Error Resume Next
For Each file In fso.GetFolder(Folder).Files '遍历文件
file.Name = newBats(re.Execute(file.Name).Item(0).Value) & ".bat" '保持对应顺序的重命名
Next
MsgBox "OK"
欢迎光临 批处理之家 (http://bathome.net./) | Powered by Discuz! 7.2 |