-
原图
-
修改后
'批量修改文件名.vbs
Function GetScriptPath()
GetScriptPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
End Function
Class MyFileOperator
Private obj
Private Sub Class_Initialize()
Set obj = CreateObject("Scripting.FileSystemObject")
End Sub
Private Sub Class_Terminate()
Set obj = Nothing
End Sub
' 枚举文件
Public Function ListFiles()
Dim path :path = GetScriptPath()
Dim objFolder : Set objFolder = obj.GetFolder(path)
Dim files()
Dim i :i = 0
For Each objFile in objFolder.Files
ReDim Preserve files(i)
files(i) = objFile.Name
i = i + 1
Next
Set objFolder = Nothing
ListFiles = files
End Function
' 文件改名
Public Sub ChangeFileName(source, dest)
Call obj.MoveFile(source, dest)
End Sub
End Class
Dim fop :Set fop = New MyFileOperator
Dim files :files = fop.ListFiles() '
Dim prefix : prefix = InputBox("请输入文件名前缀,文件名=你输入的名称_图片序号") '获取用户输入的前缀
Dim suffix : suffix = InputBox("请输入文件名后缀") '获取用户输入的后缀
Dim getReturn
getReturn = MsgBox("确定要更改名称?", vbInformation + vbOKCancel, "警告提示")
if getReturn = vbOK then
Dim i
'更改名称
For i = 0 To UBound(files)
if files(i) <> "批量修改文件名.vbs" then '不将代码本身文件修改
Call fop.ChangeFileName(files(i), prefix &"-"& i &"."& suffix)
end if
Next
end if
&
是字符连接符prefix &"_"& i &"."& suffix
就是要改的名字,不需要_
可以直接删除- 在当前文件夹创建名为
批量修改文件名.vbs
的文件,防止把自己也改没了 - 原文:zhidao.baidu.com/question/303882361.html