Skip to content

Instantly share code, notes, and snippets.

@jay16
Created December 27, 2013 03:41
Show Gist options
  • Save jay16/8142294 to your computer and use it in GitHub Desktop.
Save jay16/8142294 to your computer and use it in GitHub Desktop.
把D:\test\目录下的所有jpg文件重命名为pic###.jpg的代码:
Dim i As Integer
i = 1
Set fs = CreateObject("scripting.filesystemobject")
Set fd = fs.GetFolder("d:\test")
For Each f In fd.Files
If LCase(f.ShortName) Like "*.jpg" Then
f.Name = "pic" & Format(i, "000") & ".jpg"
i = i + 1
End If
Next
如果文件名已确定,可以用Set f=fs.GetFile搜索("[完整路径和文件名]"),然后用f.Name="[新文件名]"
另外提问的时候要注意把已知的条件和要达到的效果说清楚,“已知文件名的若干文件”到底是什么样的文件名,有没有什么规律?是否在同一文件夹下?或者是否已将文件名存放在一个字符串数组中?不说清楚别人怎么能帮你,只能给你一个实现的思路了
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment