Editor of parameters for a batch file (BAT) under Windows
Batch parameters can be used anywhere within a batch file.
The batch parameter extension variable (%0 to%9). When a batch parameter is used in a batch file, the%0 will be replaced by the batch file name, and%1 to%9 will be replaced by the corresponding parameter typed at the command line.
You can use an edit character in a batch parameter. The editor uses the current drive and directory information to extend the batch parameter to a partial or complete file or directory name. To use the edit character, type the percent sign (%) character, followed by the tilde (~) character, and then type the appropriate editor (that is,%~modifier).
The following table lists the editor characters that you can use in the extension.
Edit character |
Description |
%~ |
%~1 extend%1 and remove any quotation marks (") |
%~f |
%~f1 extending%1 to a fully qualified path name |
%~d |
%~d1 extending%1 to drive letter |
%~p |
%~p1 extending%1 to the path |
%~n |
%~n1 extending%1 to file name |
%~x |
%~x1 extending%1 to a file name extension |
%~s |
The path to the%~S1 extension contains only the short name |
%~a |
%~a1 extending%1 to file properties |
%~t |
%~t1 extending%1 to file date/time |
%~z |
%~z1 extending%1 to file size |
%~ $PATH: |
%~ $PATH: 1 searches the directory listed in the PATH environment variable and expands%1 to the fully qualified name of the first found directory. If the environment variable name is not defined or the file is not found, the editor expands to an empty string |
The following table lists the possible combinations of editors and qualifiers that you can use to get complex results:
Edit character |
Description |
%~dp0 |
The%0 Extended to drive letter + path + file name + extension |
%~nx1 |
Extend%1 to file name and extension |
%~dp$path:1 |
Search for% 1 in the directory listed in the PATH environment variable, and expand to the drive letter and path of the first found directory |
%~dpn0 |
Extend%0 to drive letter + path + file name |
%~ftza1 |
Extending%1 to an output line similar to Dir |
Note: In the example above, you can replace%1 and PATH with other batch parameters.
The%* editor is the only editor that can represent all parameters passed in a batch file. You cannot use this editor with the%~ edit character combination. The%~ syntax must be terminated by a valid parameter value.
You cannot use batch parameters in the same way as you use environment variables. You cannot search for or replace a value, or check a substring. However, you can assign a parameter to an environment variable and then use that environment variable.
"Transcription, collection" editor of parameters for a batch file (BAT) under Windows