Overview
This rename preset is for people who keep multiple versions of the Opus installers. It automatically adds the Opus version details to the installer filenames.
This is an example of how to use the OnGetNewName Rename script function introduced in Directory Opus 11. Using the newer function gives you easy access to file metadata, which the script uses to get the exe's version numbers. (Previously, you would have had to use {...} codes in the New Name field to "smuggle" metadata into the script. Now scripts can access metadata more directly.)
The script is highly specific to Opus and expects the input to have a name like "DOpusInstall.exe" (and a language if it is not the Universal installer). If the input file is not named in that way then it will be skipped over. (Of course, you can adapt the script to work with other installers and naming conventions.)
Download
- Opus Installer.orp (1.8 KB)
- See: How to use Rename Presets from this forum
History
v3 - 31 Jan 2020
- Updated to work with the new "DOpusInnoInstall.exe"-style filenames.
v2 - 01 Aug 2015
- No longer adds 32-bit and 64-bit to the end of names, since Opus now uses a single unified 32/64-bit installer.
v1 - 27 Jun 2014
- First release.
Script code
Here is the script, so that people browsing the forum for scripting techniques do not have to download and inspect the archive. If you just want to use the script, ignore this part and use the download above.
Option Explicit
Function OnGetNewName ( ByRef GetNewNameData )
OnGetNewName = False ' No rename if we exit early.
If GetNewNameData.item.is_dir Then
Exit Function
End If
Dim nameRemain
nameRemain = GetNewNameData.item.name
Dim baseName
If UCase(Left(nameRemain,12)) = "DOPUSINSTALL" Then
baseName = Left(nameRemain,12)
nameRemain = Mid(nameRemain,13)
ElseIf UCase(Left(nameRemain,16)) = "DOPUSINNOINSTALL" Then
baseName = Left(nameRemain,16)
nameRemain = Mid(nameRemain,17)
Else
Exit Function
End If
If UCase(Right(nameRemain,4)) = ".EXE" Then
nameRemain = Left(nameRemain,Len(nameRemain)-4)
Else
Exit Function
End If
Dim langString
If Len(nameRemain) = 0 Then
langString = ""
ElseIf Len(nameRemain) > 1 And Left(nameRemain,1) = "-" Then
langString = " - " & Right(nameRemain,Len(nameRemain)-1)
Else
Exit Function
End If
If GetNewNameData.item.metadata <> "exe" Then
Exit Function
End If
Dim verString
verString = GetNewNameData.item.metadata.exe.prodversion
Do While Right(verString,2) = ".0"
verString = Left(verString, Len(verString)-2)
Loop
Dim majorVersion
majorVersion = Left(verString,2)
' OnGetNewName = "F:\Essentials\tools\Directory Opus\Opus " & majorVersion & "\DOpusInstall - " & verString & langString & ".exe"
OnGetNewName = baseName & " - " & verString & langString & ".exe"
End Function