Dir Command by Extension

C

CT

from the command line, I am trying to list only files
that have the extension .TXT using the command:

dir *.TXT

also returns files ending in .TXT1 & .TXT2.

Is there a way to force the command to return only files
with the EXACT extension I specify?

(NOTE: I am looking for a command line solution, I
realise that the windows "search utility" would provide
the results I am looking for).
 
S

Smile Extender

My opinion is that this is bug in windows. Anyway, there is at least one
solution:

dir *.log | findstr /r "TXT$"

Trick is to pipe dir's output to findstr command, which is normally used to
find strings from files. Swithc /r means that you want to use regular
expressions in search string. That "TXT$" means that only lines ending with
"TXT" will be listed. Use findstr /? to get more help.

/nico
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top