# DOS command to find the filecount



## Codesearcher (May 13, 2009)

I need a DOS command to find the count of files with specific pattern in a directory

Eg:
C:\Test has
cartest1_12.txt
cartest2_12.txt
cartest3_12.txt
test1.txt
test2.txt

and if i search for cartest*.txt
the result should be 3
and if i search for test*.txt
the result should be 2

pls help me


----------



## TheOutcaste (Mar 19, 2009)

*Dir /B test*.txt|Find /C /V "?"*
This displays the count of lines that do not contain a *?* symbol. Since file names can't contain a *?*, this will count all the files that the Dir command found.
Here's a script that checks for the two items in your example and displays the count for each:

```
@Echo Off
Set _Folder=C:\Temp Dir\Test
Set _Search=test*.txt
Call :_Count "%_Folder%" "%_Search%"
Set _Search=cartest*.txt
Call :_Count "%_Folder%" "%_Search%"
Goto :EOF
:_Count
PushD "%~1"
For /F "Tokens=* Delims=" %%I In ('Dir /B /S "%~2" 2^>Nul^|Find /V /I /C "?"') Do Set _Num=%%I
PopD
Echo "%_Search%" was found %_Num% Time(s)
```


----------

