Rename Opus installers to include version

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

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

When this hoary old topic came up some years ago, you sagely suggested using the {prodversion} rename.

Ever since then I have had a Standard Rename

Old name
*.exe

New name

  • {prodversion}.exe

Works a treat. Not as fancy as this one, but probably adequate for many users.

PS I like the old one because it works with many software packages that I retrieve.

Appending {prodversion} is still good for the general case.

(With the Opus installers, it would mean the 32-bit and 64-bit ones were segregated, instead of kept together for each version. Same for the languages. But if you don't keep more than one installer per release, then that makes no difference, and what you were using is just as good.)

Can this be update for the new version that now include both x32 and x64

@michaelkenward: I wanted to add the prodversion to an already existing rename-preset, but it doen't work here (it adds just {prodversion} to the name).

Done. New version in the root post.

Root post updated to work with the new "DOpusInnoInstall.exe"-style filenames.