Reputation: 57
I have a group of files that are named as such (word can be any word or numbers):
Word word-word word word Floor B2342 Word Word-word.pdf
Word word-word word Floor: B-2342 Word Word-word.pdf
Word word- Floor C43 Word Word.pdf
Word word word- Floor- E2AD342 Word Word.pdf
I want to rename everything in the folder to only have the group that follows Floor... You can count on Floor always being in the file name and what I want to keep following floor.
B2342.pdf
B-2342.pdf
C43.pdf
E2AD342.pdf
Upvotes: 1
Views: 1427
Reputation: 9309
Pass the path of the folder you want to process as the first argument to this script. You might have to tweak the regular expression for your input.
Set expr = New RegExp
Set fs = CreateObject("Scripting.FileSystemObject")
Set fpath = fs.GetFolder(WScript.Arguments(0))
expr.Pattern = "Floor\S*\s+([^\s.]*)"
For Each fspec In fpath.Files
Set matches = expr.Execute(fspec.Name)
If matches.Count = 0 Then
WScript.StdErr.WriteLine "Invalid file name " & fspec.Name
Else
fspec.Move fspec.ParentFolder & "\" & matches(0).Submatches(0) & ".pdf"
End If
Next
Upvotes: 3