%~ (percent tilde)

suggest change

When a command-line argument contains a file name, special syntax can be used to get various information about the file.

The following expand to various information about the file passed as %1:

SyntaxExpansion ResultExample
%~1%1 with no enclosing quotation marksNot provided
%~f1Full path with a drive letterC:\Windows\System32\notepad.exe
%~d1Drive letterC:
%~p1Drive-less path with the trailing backslash\Windows\System32\
%~n1For a file, the file name without path and extensionFor a folder, the folder namenotepad
%~x1File name extension including the period.exe
%~s1Modify of f, n and x to use short nameNot provided
%~a1File attributes--a------
%~t1Date and time of last modification of the file02.11.2006 11:45
%~z1File size151040
%~pn1A combination of p and n\Windows\System32\notepad
%~dpnx1A combination of several lettersC:\Windows\System32\notepad.exe
%~$PATH:1The full path of the first match found in the folders present in the PATH variable, or an empty string in no match. 
%~n0%~n applied to %0:The extensionless name of the batchtildetest
%~nx0%~nx applied to %0:The name of the batchtildetest.bat
%~d0%~f applied to %0:The drive letter of the batchC:
%~dp0%~dp applied to %0:The folder of the batch with trailing backslashC:\Users\Joe Hoe\

The same syntax applies to single-letter variables created by FOR command, such as %%i.


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents