Inside Man
Inside Man

Reputation: 4297

VBScript To Remove Number from filename

I'm looking for a VBscript which scan a folder for files and remove number from filenames. for example if we have a file named "target1990.txt" then It should be "target.txt"

Can anyone help please?

Upvotes: 0

Views: 510

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

Use a RegExp that looks repeatedly/globally for a sequence of digits (\d+) and replace all matches with "" (nix):

>> set r = New RegExp
>> r.Global = True
>> r.Pattern = "\d+"
>> s = "target1990.txt"
>> WScript.Echo s, r.Replace(s, "")
>>
target1990.txt target.txt

further sample (same regexp):

>> s = "t1ar33get19s90.txt"
>> WScript.Echo s, r.Replace(s, "")
>>
t1ar33get19s90.txt targets.txt

Upvotes: 2

Related Questions