RegEx and Scripts - How to call Two Scripts in Series?

I have two (or more) rename scripts. How can I call one after another in one operation? I am not a programmer and don't know how to call one script from within another.

Script 1:

option explicit

Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )

  Dim regex
  Dim strExtension
  Dim strNameOnly

  ' Create a RegExp object
  Set regex = new RegExp
  regex.IgnoreCase = True ' Ignore Case-sensitive matching.
  regex.Global = True ' All matches will be replaced, not just the first match.
 
  ' 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
 

  '----------------------
  ' Renaming
  '----------------------
 
  ' Replace Dots, except between numbers
  regex.Pattern = "([^0-9]|[0-9])\.([^0-9]| )"      'Example: Nero.v8.2.[Build.123].zip --> Nero v8.2 [Build 123].zip
  strNameOnly = regex.Replace(strNameOnly, "$1 $2") '
  strNameOnly = regex.Replace(strNameOnly, "$1 $2") 'repeat search from begining for losed rplaces
  regex.Pattern = "([^0-9])\.([0-9])"               'Example: BootCD.8.2.iso --> BootCD 8.2.iso
  strNameOnly = regex.Replace(strNameOnly, "$1 $2")
  strNameOnly = regex.Replace(strNameOnly, "$1 $2") 'repeat search from begining for losed rplaces

  ' Rejoin the name and extension (to lower case) and we're finished
  strNewName = strNameOnly & LCase(strExtension)
               
End Function

...and then run Script 2:

option explicit

' ********************************************************
'  TitleCase by Steve Banham (tanis@dopus.com) 07-Apr-2007
'  Modified by Leo Davidson (www.pretentiousname.com)
' ********************************************************
'                    General Options
' ********************************************************
dim fOddChars
dim fMultiSpace
dim fUnderscore
dim fStripSpaces
dim fExtLCase
dim fHyphens

fOddChars = True        ' Replace %20 with spaces
fMultiSpace = True      ' Remove multiple spaces
fUnderscore = True      ' Replace "_" with a space
fStripSpaces = True     ' Strip leading/trailing spaces
fExtLCase = True        ' Make extension lower case
fHyphens = True         'Replace hyphens with spaces
' ******************************************************
'                   TitleCase Options
' ******************************************************
' fTitleCase MUST be True for the other options in this
' section to work
' ******************************************************
dim fTitleCase
dim fParCap
dim fDashCap
dim fFullStopCap
dim fFirstNonNum

fTitleCase = True       ' Convert to true titlecase
fParCap = True          ' Capitalise after parenthesis
fDashCap = True         ' Capitalise after a dash
fFullStopCap = True     ' Capitalise after a full stop
fFirstNonNum = True	' Capitalise first non-numeric

' ******************************************************

Function Rename_GetNewName ( strFileName, strFullPath, _
		fIsFolder, strOldName, ByRef strNewName )

	' Write the name of the script to the Output window
	Dopus.OutputString "TitleCase by Steve Banham 07-Apr-2007"

	dim strExt
	dim iOldLength
	dim iNewLength
	dim strNameArray
	dim strTmpWord
	dim strTmpName
	dim x
	dim j
	dim i

	'Strip the filename extension for now
	if fIsFolder = False then
		if InStr(strNewName, ".") then
			strExt = Right(strNewName, Len(strNewName)-(InStrRev(strNewName, ".")-1))
			strNewName = Left(strNewName, InStrRev(strNewName, ".")-1)
			' Convert extension to lowercase while we're at it
			if fExtLCase = True then
				strExt = LCase(strExt)
			end if
		else
			strExt = ""
		end if
	end if

	' Replace "_" with spaces
	if fUnderscore = True then
		strNewName = Replace(strNewName, "_", " ")
	end if
	
	' Replace "-" with spaces
	if fHyphens = True then
		strNewName = Replace(strNewName, "-", " ")
	end if

	' Replace "%20" with spaces
	if fOddChars = True then
		strNewName = Replace(strNewName, "%20"," ")
	end if
	
	' Remove all multiple spaces
	if fMultiSpace = True then
		iNewLength = 0
		iOldLength = len(strNewName)
		Do While iOldLength > iNewLength
			iOldLength = len(strNewName)
			strNewName = Replace(strNewName,"  "," ")
			iNewLength = len(strNewName)
		Loop
	end if

	' Trim spaces at start/end of filename (e.g. because it used to start with a an underscore)
	strNewName = Trim(strNewName)

	' Convert filename to TitleCase
	if fTitleCase = True then
		' Create an array from words in the filename
		strNameArray = split(strNewName, " ")

		' Now go through each item in the array and process it
		if ubound(strNameArray) > 0 then
			for x = lbound(strNameArray) to ubound(strNameArray)
	
				' Set all text to lower case to begin with
				strNameArray(x) = LCase(strNameArray(x))

				' Ignore articles, prepositions and conjunctions
				Select Case strNameArray(x)
					Case "a"
					Case "an"
					Case "at"
					Case "and"
					Case "but"
					Case "by"
					Case "for"
					Case "in"
					Case "into"
					Case "is"
					Case "of"
					Case "off"
					Case "on"
					Case "onto"
					Case "or"
					Case "the"
					Case "to"
					Case "it"
					Case else
						if len(strNameArray(x)) > 0 then

							strTmpWord = Ucase(mid(strNameArray(x),1,1)) & mid(strNameArray(x),2,len(strNameArray(x))-1)

							' If the word begins with "(" then capitalise the next letter
							if mid(strNameArray(x),1,1) = "(" then
								if fParCap = True then
									strTmpWord = Ucase(mid(strNameArray(x),1,2)) & mid(strNameArray(x),3,len(strNameArray(x))-1)
								end if
							end if
							
							' If the word follows a "-" then it needs to be capitalised
							if mid(strNameArray(x),1,1) = "-" then
								if fDashCap = True then
									strTmpWord = Ucase(mid(strNameArray(x),1,2)) & mid(strNameArray(x),3,len(strNameArray(x))-1)
								end if
							end if

							strNameArray(x) = strTmpWord
						end if
				end Select
			next
		Else
			strNameArray(0) = LCase(strNameArray(0))
		End if

		' Make sure the first word is capitalised
		strTmpWord = Ucase(mid(strNameArray(0),1,1)) & mid(strNameArray(0),2,len(strNameArray(0))-1)
		strNameArray(0) = strTmpWord

		' Clear the new name variable
		strNewName = ""

		' Rebuild the array into one string
		For x = lbound(strNameArray) To ubound(strNameArray)
			strNewName = strNewName & strNameArray(x) & " "
		Next

		' Capitalise after - when it's in the middle of words
		' Capitalise after - when it's between words
		if fDashCap = True then
			For j = 1 to len(strNewName)
				if mid(strNewName,j,1) = "-" then
					strTmpName = strTmpName & mid(strNewName,j,1)
					j=j+1
					if mid(strNewName,j,1) = " " then
						strTmpName = strTmpName & mid(strNewName,j,1)
						j=j+1
					end if
					strTmpName = StrTmpName & Ucase(mid(strNewName,j,1))			
				else
					strTmpName = strTmpName & mid(strNewName,j,1)
				end if
			Next
			strNewName = strTmpName
			strTmpName = ""
		end if			

		' Capitalise after full stops in the middle of and between words
		if fFullStopCap = True then
			For i = 1 To len(strNewName)
				if mid(strNewName,i,1) = "." then
					strTmpName = strTmpName & mid(strNewName,i,1)
					i=i+1
					if mid(strNewName,i,1) = " " then
						strTmpName = strTmpName & mid(strNewName,i,1)
						i=i+1
					end if
					strTmpName = StrTmpName & Ucase(mid(strNewName,i,1))			
				else
					strTmpName = strTmpName & mid(strNewName,i,1)
				end if
			Next
			strNewName = strTmpName
			strTmpName = ""
		end if

		' Capitalise first non-numeric, non-space character.
      		' This is for music files like "07 By My Side.flac" which don't have a dash after their track numbers.
		if fFirstNonNum = True then
			For i = 1 to len(strNewName)
         			if (not IsNumeric(mid(strNewName,i,1))) and mid(strNewName,i,1) <> " " then
            				strNewName = mid(strNewName,1,i-1) & Ucase(mid(strNewName,i,1)) & mid(strNewName,i+1)
            				exit for
         			end if
      			Next
		end if
	end if
	
	' Strip leading/trailing spaces
	if fStripSpaces = True then
		strExt = Trim(strExt)
		strNewName = Trim(strNewName)
	end if
	
	' Rejoin the name and extension and we're finished
	strNewName = strNewName & strExt
								
End Function

....thanks to original coders....not my scripts, just my mashup of someone else's so don't ask me for help :slight_smile:

Thanks,
Scott

I haven't tried or tested this... so it may not work. But, My first suggestion would be to add each of these rename scripts as separate "User-defined Commands". You can access these by going to Settings->Customize Toolbars and then clicking on the "Commands" tab.

If you name the separate commands for each of the scripts "script1" and then "script2"... you could then see what happens if you call each of those user-commands from a button that did something like:

script1 script2
...or something similar.

Thank you for the button suggestion but it didn't work. Is that all I have to put in the script to call another script...just the name? No special syntax to call it?

If you already have the two scripts created as Rename Presets (in the list on the right of the Rename dialog) then the easiest thing is probably to make a command that calls each preset in turn. Then you don't have to edit the scripts themselves, and you can still use them individually when needed as well.

Please link your account if you need step-by-step help in making the command.

1 Like