|
![]() |
| 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
![]() | ![]() |