Follow Me On...
« Java Packaging / Deployment Tools I Recently Came Across | Main | Apache2: Allowing Directory Listings for a Particular Directory »
Friday
Oct202006

VBS Script Code for File Versions

I had written build scripts for various products and the end result is typically some archive file (zip,msi,iso). My build scripts would create a file such as someproduct.zip but i wanted something todo someproduct-v2.x.x.zip.

That’s what the script below does.

' Author: Blake Robertson (10-21-06)
' 
' This script gets the file version of a particular file.  
' It then renames (or copies) the file with a versioned suffix.
' 
' Example: say test.EXE had a version of 2.1.95.0 and based on that you wanted
' to rename testPackage.zip to testPackage-v2.1.95.0"
'
' To do so, then set:
'    versionedFilePath = "test.exe"
'    nonversionedFilename = "testPackage.zip"
' 
' REQUIREMENTS: the original filename cannot have more then one '.' in it.' 
Dim versionedFilePath, nonversionedFilename, seperator

'### CUSTOMIZE THE FOLLOWING 3 LINES ###
versionedFilePath = "c:\path\to\exe"
nonversionedFilename = "c:\path\to\nonversioned\file.zip"
seperator = "-v"

Dim verStr, versionedFileName, filenameArr
Set FS = CreateObject("Scripting.FileSystemObject")
verStr = FS.GetFileVersion( versionedFilePath )

' Seperates filename from file extention
filenameArr = Split( nonversionedFilename, "." )

versionedFileName = filenameArr(0) & seperator & verStr & "." & filenameArr(1)

' Renames the Original File, if copy is desired then uncomment 2nd line and comment first
'FS.MoveFile nonVersionedFileName, versionedFileName
FS.CopyFile nonVersionedFileName, versionedFileName

If your project doesn’t create versioned executable files but you can obtain information from registry key or from a file, then replace the verStr = FS.GetFileVersion(…) line above with one of the snippets below:

Read Version Info in from a registry key:

verStr = WshShell.RegRead("HKLM\SOFTWARE\Your Company\Your Product\Version")

Snippet to read version info from a text file.

Set FS = CreateObject(“Scripting.FileSystemObject”)
verStr = FS.OpenTextFile(“version.txt”).ReadAll

Tip for SVN Users

If you are using SVN or some file versioning system, you can get version info by calling the update command twice. The second time redirect the output to a txt file. The second consecutive call to update will not update any files so the output should be just an informative version note.
svn update myCodeDir 
svn update myCodeDir > version.txt
type version.txt
At revision 342.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.