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.
Description of the edit character
%~%~1 expands%1 and removes any quotation marks (""
%~f%~f1 to extend%1 to 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 file name extension
The path to the%~s%~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:
Description of the edit character
%~dp0 will%0 Extended to drive letter + path + file name + extension
%~nx1 extending%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 extension%0 to drive letter + path + file name
%~ftza1 extending%1 to output line similar to Dir
Attention:
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.