主题:同一文件夹下的重命名问题
下面是在同一个文件夹下重命名的代码,但我试验了N个文件类型,发现gif、ico无法重命名,而bmp、txt、jpg、png、wmf、tif、mid、wav、mp3等都可以,不知各位是否遇到过同样问题?你们是如何解决的?
Private Sub Command1_Click()
Dim fso, folder, files, file
Dim num As Integer, ext1 As String, ext2 As String
Set fso = CreateObject("scripting.filesystemobject")
Set folder = fso.getfolder("J:\一江秋水的文档\新建文件夹")
Set files = folder.files
ext1 = "jpg" '欲改名的文件名后缀
num = 1 '文件名起始序数
For Each file In files
Do
ext2 = fso.getExtensionName(file)
If LCase(ext2) <> ext1 Then Exit Do
If Not fso.fileexists(folder & "\" & num & "." & ext2) Then
file.Name = num & "." & ext2
Exit Do
Else
num = num + 1
End If
Loop
Next
End Sub
Private Sub Command1_Click()
Dim fso, folder, files, file
Dim num As Integer, ext1 As String, ext2 As String
Set fso = CreateObject("scripting.filesystemobject")
Set folder = fso.getfolder("J:\一江秋水的文档\新建文件夹")
Set files = folder.files
ext1 = "jpg" '欲改名的文件名后缀
num = 1 '文件名起始序数
For Each file In files
Do
ext2 = fso.getExtensionName(file)
If LCase(ext2) <> ext1 Then Exit Do
If Not fso.fileexists(folder & "\" & num & "." & ext2) Then
file.Name = num & "." & ext2
Exit Do
Else
num = num + 1
End If
Loop
Next
End Sub