删除文件名vbsript中的数字和句点



我已经找到了一个脚本,它将替换我在脚本中编写的下划线(_)和其他文本。我需要修改这个脚本,这样它也会删除文件名中的所有数字。我尝试了[0-9]和/d,但没有删除文件名中的数字。我还试图删除文件名中的句点,但这也删除了文件扩展名。所以它也拿走了.csv。有人能帮忙吗?

'========================================================
' VBScript to replace underscore in file name with space 
' for each files in a folder
' Written by ApOgEE of http://coderstalk.blogspot.com
'========================================================
Dim sName
Dim fso
Dim fol
' create the filesystem object
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
' get current folder
Set fol = fso.GetFolder(".")
' go thru each files in the folder
For Each fil In fol.Files
    ' check if the file name contains underscore
    If InStr(1, fil.Name, "_") <> 0 Then
        ' replace underscore with space
        sName = Replace(fil.Name, "_", " ")
        ' rename the file
        fil.Name = sName
    End If
Next
' echo the job is completed
WScript.Echo "Completed!"

Replace函数只执行简单的字符串替换。它不支持通配符或模式。您正在查找正则表达式:

Set re = New RegExp
re.Pattern = "[0-9_.]"
re.Global  = True
For Each fil In fol.Files
  fil.Name = re.Replace(fil.Name, " ")
Next

最新更新