1

For example if type cmd.exe echo %1 it shows the filename and extension of the selected file. But what I want to do is just get the extension of the selected file by itself.

Does anybody know how?

1

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 

Source

  • 1
    Maybe others want to know how you got it? – nixda Jul 4 '13 at 23:00
1

You can do this in Powershell easily, using the Extension attribute.

One example (Although many more methods to accomplish this are possible:

Get-ChildItem | select Extension

And in cmd.exe:

for %i in (*.*) do echo "%~xi"
  • added DIR command – Austin T French Jul 4 '13 at 17:52
  • Sorry I type the wrong command is " cmd.exe echo %1" and explaining again what i want is get only the extension of any file I select, and not for a specific extension,for all extensions. "for example if type cmd.exe echo %1 ,it shows the filename and extension of the selected file" I want to create a context menu option with a similar option but i need to print only the extension – LRR Jul 4 '13 at 17:57
  • Alright, updated with that in mind. – Austin T French Jul 4 '13 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.