YES!! I finally found a way to replace my old file renaming tool. The reason why I could not use the DOpus rename function is because of how standard rename dialog handles duplicate names 1) It does not allow you to preview changes 2) It uses an auto number with parentheses rather than allowing a custom format. But now I finally was able to write a script!
My script adds all the previous new names to a string and then regex checks the string before generating a name for the second file. Based on the number of times it encounters that name already in the string, it adds that number to the ending of the file name. Although it seems to work extremely well, I see two scenarios where this may be a problem and just wanted to share the script and get feedback if there is an obvious way to get around one or both of those minor issues.
-
You cannot have an infinite number of characters in a string variable. So possibly if I try to rename over 1k files, the sting will go blank (I experienced this in another piece of Metatags code).
-
If you do not select all files in the folder and one of the files not selected may have a duplicate name, you will get an error to a duplicate file exists.
[code]Option Explicit
Dim newNameString
newNameString = Empty
Function OnGetNewName (ByRef GetNewNameData)
Dim item, itemName, newName, meta, fileName, createdDate, re0, re1, re1Match, re1Count
Set item = GetNewNameData.item
Set meta = item.metadata
itemName = item.name_stem
newName = Empty
Set re0 = new RegExp
re0.Pattern = ".*(20[0-2][0-9])\D?([0-1][0-9])\D?([0-3][0-9])\D?([0-2][0-9])\D?([0-5][0-9])\D?([0-5][0-9]).*"
re0.IgnoreCase = True
If (re0.Test(itemName)) Then
newName = re0.Replace(itemName, "$1-$2-$3_$4-$5-$6")
Else
newName = itemName
End If
Set re1 = new regExp
re1.Pattern = newName
re1.IgnoreCase = True
re1.Global = True
Set re1Match = re1.Execute(newNameString)
re1Count = re1Match.count
DOpus.Output re1Count
If (re1.Test(newNameString)) Then
If re1Count < 10 Then
newName = newName & "_0" & re1Count
Else
newName = newName & "_" & re1Count
End If
End If
If newNameString = Empty Then
newNameString = newName
Else
newNameString = newNameString & "," & newName
End If
If (newName <> Empty) Then
'OnGetNewName = newName & item.ext
OnGetNewName = newName & LCase(item.ext)
Else
OnGetNewName = True
End If
End Function
'http://www.robvanderwoude.com/vbstech_regexp.php[/code]