32

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?

dayuloli
  • 16,205
  • 16
  • 71
  • 126
Marc
  • 321
  • 1
  • 3
  • 3

4 Answers4

38

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$
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
4

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

Tomer Gabel
  • 4,104
  • 1
  • 33
  • 37
0

dir C:\XML /s /b | findstr /e .xml > C:\XML\list.txt

this works for me, just change the .xml extension to .txt

0

Splitting the commands for better understanding:

dir /s /b 
     ^  ^
     |  |
     |  Displays a **bare** list of directories and files, with no additional information.
     |
      ~ Lists every occurrence of the specified file name within the 
        specified directory and all **subdirectories**.


findstr /e
        ^
        |
        Matches the text pattern if it is at the **end** of a line.
Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79