Some colleague from this forum once provided me these two codes, which might be helpful:
[code]Rename TO="{DlgStringS|AN welcher Stelle soll von hinten etwas eingefügt werden ?\n\ndurch ein Komma getrennt\n\nWAS soll eingefügt werden ?|2,Neuer Text}" AUTORENAME
@nodeselect
@script vbscript
option explicit
Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )
Dim strNameOnly
Dim strExtension
Dim intComPos ' Location of the leftmost comma in dialog box entry
Dim strText ' Extracted Text from dialog box entry
Dim strCount ' Extracted number (of places from left) from dialog box entry
' If we're renaming a file then remove the extension from the end and save it for later.
if fIsFolder or 0 = InStr(strFileName,".") then
strExtension = ""
strNameOnly = strFileName
else
strExtension = Right(strFileName, Len(strFileName)-(InStrRev(strFileName,".")-1))
strNameOnly = Left(strFileName, InStrRev(strFileName,".")-1)
end if
' Find the leftmost comma
intComPos = InStr(strNewName,",")
if intComPos > 0 then
strCount = Trim(Left(strNewName, intComPos-1))
strText = Right(strNewName,Len(strNewName)-intComPos)
end if
Dim I
Dim Dots
Dots = ""
if CInt(strCount) > 0 then
I = 1
While I < CInt(strCount)
Dots = "." & Dots
I = I+1
Wend
Dots = "(" & Dots & ")"
else
' Character position was not more than 0 - set LeftDots to an invalid value so rename fails
Dots = "(8SCaO4fOzy5hy4Fs2CxBGCPy6oAl2Hp988ZH9C3toox0HWlmOA)"
end if
Dim regex
' Create a RegExp object
Set regex = new RegExp
regex.Pattern = "(.*)" & Dots
strNameOnly = regex.Replace(strNameOnly, "$1" & strText & "$2") '
strNewName = strNameOnly & strExtension
End Function
[/code]
or
[code]Rename TO="{DlgStringS|An welcher Stelle soll von hinten etwas entfernt werden ?\n\ndurch ein Komma getrennt\n\nWIEVIELE Stellen sollen entfernt werden ?|2,5}" AUTORENAME
@nodeselect
@script vbscript
option explicit
Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )
Dim strNameOnly
Dim strExtension
Dim intComPos ' Location of the leftmost comma in dialog box entry
Dim strLeftNum ' Extracted left number from dialog box entry
Dim strRightNum ' Extracted right number from dialog box entry
' If we're renaming a file then remove the extension from the end and save it for later.
if fIsFolder or 0 = InStr(strFileName,".") then
strExtension = ""
strNameOnly = strFileName
else
strExtension = Right(strFileName, Len(strFileName)-(InStrRev(strFileName,".")-1))
strNameOnly = Left(strFileName, InStrRev(strFileName,".")-1)
end if
' Find the leftmost comma in dialog box entry
intComPos = InStr(strNewName,",")
' Extract the 2 numbers from dialog box entry
if intComPos > 0 then
strLeftNum = CInt(Trim(Left(strNewName, intComPos-1)))
strRightNum = CInt(Trim(Right(strNewName,Len(strNewName)-intComPos)))
end if
Dim I ' General counter variable
Dim LeftDots ' LeftDots will become the first RegEx tagged match
LeftDots = "" ' Set LeftDots to a null value to start
' Assemble LEFT regEx dots ----------------------------------------
if strLeftNum > 0 then
I = 1
While I < strLeftNum
LeftDots = "." & LeftDots
I = I+1
Wend
LeftDots = "(" & LeftDots & ")"
else
' Character position was not more than 0 - set LeftDots to an invalid value so rename fails
LeftDots = "(8SCaO4fOzy5hy4Fs2CxBGCPy6oAl2Hp988ZH9C3toox0HWlmOA)"
end if
' ----------------------------------------------------------------------------------------
Dim ExtractAmt ' ExtractAmt will be the number of characters to remove from the file name
ExtractAmt = strRightNum
' Assemble EXTRACTION dots ----------------------------------------
Dim ExtractDots ' ExtractDots will become the second RegEx tagged match
ExtractDots = "" ' Set ExtractDots to a null value to start
I = 0
if ExtractAmt > 0 then
While I < ExtractAmt
ExtractDots = "." & ExtractDots
I = I+1
Wend
ExtractDots = "(" & ExtractDots & ")"
else
' Amount to extract was not more than 0 - set ExtractDots to an invalid value so rename fails
ExtractDots = "(loY8TbEarTKFM5jKdd6pOoqAtm8ptx1zN2lx0ooB)"
end if
' ----------------------------------------------------------------------------------------
Dim regex
' Create a RegExp object
Set regex = new RegExp
'if fIsFolder = True then ' If it's a folder ---------------------------------------
regex.Pattern = "(.)" & ExtractDots & LeftDots
'else ' If it's a file -----------------------------------------
'regex.Pattern = LeftDots & ExtractDots & "(...*)"
'end if
strNameOnly = regex.Replace(strNameOnly, "$1$3") '
strNewName = strNameOnly & strExtension
End Function
[/code]