使用 wildcards/regular 表达式重命名文件

Renaming files with wildcards/regular expressions

我有一个名为 SampleTestFile.ghi 的文本文件。在程序处理此文件后,它被重命名并移动到另一个文件夹中。重命名文件时使用的命名约定是 *.abc

所以我有文件名(SampleTestfile.ghi),我有命名约定(*.abc),但是如何使用[=20=将原始文件名转换为处理后的文件名]?有什么办法可以说

ProcessFileName = "SampleTestFile.ghi" & "*.abc" 
''and get the correct answer of SampleTestFile.abc ?
ProcessFileName = Replace(sampleTestFileName, ".ghi",".abc")

假设“.ghi”从不出现在文件名的中间

使用起来可能更安全Mid()

Sub Test()

    Dim s
    s = "my strange filename.ghi here.ghi"

    Debug.Print "original", s

    'Method 1 (has a potential problem)
    Debug.Print "method 1", Replace(s, ".ghi", ".abc")

    'Method 2 (safer)
    Mid(s, Len(s) - 3, 4) = ".abc"
    Debug.Print "method 2", s

End Sub