JSI Tip 4890. How can I retrieve a files version in batch?


The Windows 2000 Support Tools, and the Windows XP Support Tools, contain Filever.exe,
which will return the version of a file. If you type filever %SystemRoot%\notepad.exe on Windows 2000, you receive:

----- W32i APP ENU 5.0.2140.1 shp 50,960 12-07-1999 notepad.exe and version 5.1.2600.0 on Windows XP.

I have scripted FileVersion.bat to return the Version environment variable. The syntax is:

FileVersion Fully_Qualified_FileName

Example:

FileVersion %windir%\notepad.exe sets the Version environment variable to 5.0.2140.1 on Windows 2000.

FileVersion.bat contains:

@echo off
if \{%1\}==\{\} goto syntax
if not exist %1 goto syntax
for /f "Tokens=5" %%a in ('filever %1') do set version=%%a
goto :EOF
:syntax
set version=
@echo Syntax: FileVersion FQFilename


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish