Câu trả lời:
cmd.exe echo %~x1
%* return the remainder of the command line starting at the first command line argument (in Windows NT 4, %* also includes all leading spaces)
%~dn return the drive letter of %n (n can range from 0 to 9) if %n is a valid path or file name (no UNC)
%~pn return the directory of %n if %n is a valid path or file name (no UNC)
%~nn return the file name only of %n if %n is a valid file name
%~xn return the file extension only of %n if %n is a valid file name
%~fn return the fully qualified path of %n if %n is a valid file name or directory
Bạn có thể thực hiện việc này trong Powershell một cách dễ dàng bằng cách sử dụng thuộc tính Tiện ích mở rộng.
Một ví dụ (Mặc dù nhiều phương pháp khác để thực hiện điều này là có thể:
Get-ChildItem | select Extension
Và trong cmd.exe:
for %i in (*.*) do echo "%~xi"