Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows command line search for exact extension with dir

When I do a search:

dir /b /s *.txt

I get all files/folders with the extension .txt. But I also get them when they have an extension like .txtx. How can I search for the exact extension?

like image 881
Marc Avatar asked Mar 11 '10 09:03

Marc


People also ask

How do you find the file extension in cmd?

You can also search for a particular file type by using a command dir \*. pdf /s and it will show you all files saved with the . pdf extension.

How do I search for all files with specific extensions?

For finding a specific file type, simply use the 'type:' command, followed by the file extension. For example, you can find . docx files by searching 'type: . docx'.


2 Answers

you can try this

dir  /s /b *.txt | findstr /v .txt.

or

dir  /s /b *.txt | findstr /e .txt

or

dir  /b *.txt | findstr  .txt$
like image 122
ghostdog74 Avatar answered Oct 19 '22 08:10

ghostdog74


I can't figure out why it behaves like this, but this works: dir /b /s .txt | findstr /e .txt. Ugly but works.

like image 4
Tomer Gabel Avatar answered Oct 19 '22 06:10

Tomer Gabel