下面有我用来将“..”更改为“.”的代码。例如,我有一个文件名,如“file..pdf”,我想要“file.pdf”,但它会删除所有点。我不知道如何改变它:
Function strLegalFileName2(ByVal FName) As String
Dim i As Integer
Const strIllegals = "*&..&*"
strLegalFileName2 = FName
For i = 1 To Len(strIllegals)
strLegalFileName2 = Replace(strLegalFileName2, Mid$(strIllegals, i, 1), ".")
Next i
End Function
Sub LoopThroughFiles2()
Dim FName As Variant
Dim strNew As String
Dim strDir As String
strDir = "path"
FName = Dir(strDir & "*..*")
Do While Len(FName) > 0
strNew = strLegalFileName2(FName)
If StrComp(strNew, FName) <> 0 Then Name (strDir & FName) As (strDir & strNew)
FName = Dir
Loop
End Sub