这应该让你大部分时间。您需要找出短语“If UCase(Right(objFile.Name, 4)) = ".VBP" Then" 的正确替换
目标文件也附加了“.bak”。你需要删除它。
将文件列表放在字典中的理由目前让我无法理解。我认为这与该过程经常失败有关,以至于我需要能够获取已处理文件与未处理文件的列表。
Option Explicit
Dim dicFiles
Set dicFiles = CreateObject("Scripting.Dictionary")
Private Sub AddFile(objFile)
If dicFiles Is Nothing Then
Set dicFiles = CreateObject("Scripting.Dictionary")
End If
If Not dicFiles.Exists(objFile.Path) Then
dicFiles.Add objFile.Path, "False"
End If
End Sub
Dim strRootPath 'As String
Dim objFSO 'As New FileSystemObject
Dim objFile 'As File
Dim i 'As Integer
Dim iMax 'as integer
strRootPath = "C:\Transfer"
Dim objFolder' As Folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strRootPath)
'MsgBox "" & objFolder.Files.Count & " files in folder " & objFolder.Path
For Each objFile In objFolder.Files
'MsgBox "Filespec: " & objFile.Name
If UCase(Right(objFile.Name, 4)) = ".VBP" Then
'MsgBox "Adding file " & objFile.Name
AddFile objFile
End If
Next
Dim arrFiles '() As Variant
arrFiles = dicFiles.Keys
'MsgBox "UBound(arrfiles)=" & UBound(arrFiles)
Dim fsIn 'As String
Dim fsOut 'As String
Dim strFilespec 'As String
For i = 0 To UBound(arrFiles)
Set objFile = objFSO.GetFile(arrFiles(i))
strFilespec = arrFiles(i)
fsOut = strFilespec & ".bak"
If objFSO.FileExists(fsOut) Then
objFSO.DeleteFile fsOut, True 'True = Force
End If
fsIn = strFilespec
objFSO.MoveFile fsIn, fsOut
Next
Set objFSO = Nothing