MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Batch File Tips and Tricks[Next]: Convert Long FileNames to Short (8.3)
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Tips and Tricks->Batch File Parameters

Batch File Parameters

Code Description
%* Refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...). In Windows NT 4 a leading space is added to %*. In Windows 2000 all leading spaces are removed from %*
%~1 Expands %1 removing any surrounding quotes (")
%~f1 Expands %1 to a fully qualified path name
%~d1 Expands %1 to a drive letter only
%~p1 Expands %1 to a path only
%~n1 Expands %1 to a file name only
%~x1 Expands %1 to a file extension only
%~s1 Changes the meaning of n and x options to reference the short name instead
%~a1 Expands %1 to file attributes
%~t1 Expands %1 to date/time of file
%~z1 Expands %1 to size of file
%~$PATH:1 Searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found. It does not look in the current directory and returns "" if not found.

The modifiers can be combined to get compound results:

Code Description
%~dp1 Expands %1 to a drive letter and path only
%~nx1 Expands %1 to a file name and extension only
%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %1 and expands to the drive letter and path of the first one found.
%~ftza1 Expands %1 to a DIR like output line

How to Similarly Process Environment Variables

Note that the above can also be used for environment variables via an undocumented "for" command trick demonstrated here (note that "ctext.exe" is installed by MAKEMSI which is in the path):

@echo off
set FullNameOfCtextExe=
for %%f in ("ctext.exe") do set FullNameOfCtextExe=%%~$PATH:f
if     "%FullNameOfCtextExe%" == "" echo "CTEXT.EXE" not found in PATH (weird)!
if not "%FullNameOfCtextExe%" == "" echo "CTEXT.EXE" found at: "%FullNameOfCtextExe%"

Another example:

set FileThis=C:\TMP\SomeFile.Extn
...
for %%f in ("%FileThis%") do set FileThisSN=%%~nf%%~xf

Yet another example, this one determines the "current folder":

for %%f in (".") do set FullCurrentDir=%%~ff


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006 & 2007 for the Windows SDK (Windows Installer) area.This external link was OK when tested at 27 Dec 2008Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Batch File Tips and Tricks[Next]: Convert Long FileNames to Short (8.3)


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday December 27 2008 at 3:15pm
Visit MAKEMSI's Home PageThis external link was OK when tested at 7 Dec 2008

HTML page dated Mon, 29 Jan 2007 00:11:11 GMT
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006 & 2007 for the Windows SDK (Windows Installer) area.This external link was OK when tested at 27 Dec 2008