Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' 定义文件名。
Name OldName As NewName ' 更改文件名。
OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' 更改文件名,并移动文件。
但是,Name 参数不能包括多字符 (*) 和单字符 (?) 的统配符。
所以,如果需要批量修改,就应该将 Name 语句写在对文件的遍历循环中。如下:
'文件系统递归遍历
Private Sub DoRecursion(ByVal Source As String)
Dim f, fc
Set CurrFolder = FSys.GetFolder(Source)
If CurrFolder.Attributes <> (System Or Hidden Or Directory) Then
If CurrFolder.Files.Count > 0 Then
Set fc = CurrFolder.Files
For Each f In fc
If f.Attributes <> (System Or Hidden) Then
Name f.path,DestPath
End If
Next
End If
'当前文件夹下还有子文件夹
If CurrFolder.SubFolders.Count > 0 Then
Set fc = CurrFolder.SubFolders
For Each f In fc
Call DoRecursion(f) '递归调用
Next
End If
End If
End Sub
Function Rename( _
ByVal FileName As String _
) As Integer
Return Code Description
0 Success.
2 Access denied.
8 Unspecified failure.
9 Invalid object.
10 Object already exists.
11 File system not NTFS.
12 Platform not Windows NT or Windows 2000.
13 Drive not the same.
14 Directory not empty.
15 Sharing violation.
16 Invalid start file.
17 Privilege not held.
21 Invalid parameter.