Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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

share|improve this answer
    
I got it!!! thanks for both answers. –  LRR Jul 4 '13 at 22:57
1  
Maybe others want to know how you got it? –  nixda Jul 4 '13 at 23:00

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"
share|improve this answer
    
added DIR command –  AthomSfere 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. –  AthomSfere Jul 4 '13 at 18:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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