重命名以特定模式结尾的所有文件

时间:2015-02-20 09:09:38

标签: file-io vb6

我在目录中有很多文件,它们的名称以变量模式结尾。我想将它们重命名为更短的东西。文件名的格式为:

************_A.tif
************_B.tif
************_C.tif

并希望将它们命名为:

A.tif
B.tif
C.tif

1 个答案:

答案 0 :(得分:0)

查看目录和名称功能

例如:

Private Sub Command1_Click()
  Dim strPath As String
  Dim strFile As String
  Dim strNew As String
  Dim strType As String
  Dim lngLen As Long
  'set path
  strPath = "c:\temp\test"
  'set file type
  strType = ".tif"
  'set pattern length
  lngLen = Len(strType) + 1
  'find first file
  strFile = Dir$(strPath & "\*" & strType)
  'loop through all files of the selected type
  Do Until Len(strFile) = 0
    'show current filename
    Print "File : " & strFile
    'create new filename
    strNew = Right$(strFile, lngLen)
    'show new filename
    Print "New name : " & strNew
    'rename file to new filename
    Name strPath & "\" & strFile As strPath & "\" & strNew
    'find next file
    strFile = Dir$()
  Loop
End Sub

您可能需要更改创建新文件名的行,因为可能存在获得相同新名称的文件

相关问题