Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can use dir command to check how many .txt files there are in a folder (for example, C:\Temp\)?

share|improve this question
up vote 10 down vote accepted
dir c:\temp\*.txt

This gives you a summary of the number of files matching that particular wildcard.

dir c:\temp\*.txt | find "File(s)"

If you only want to see the count and don't want to see any of the filenames.

share|improve this answer

If you need the count of files in a Batch variable for further processing, you may get it this way:

set i=0
for %%a in (*.txt) do set /a i+=1

After the for the i variable have the number of .txt files.

share|improve this answer

At the command prompt, or in the batch script, type this:

dir|find /c ".txt"

This will get a list of all the txt files in the folder...

For ways to get a count of all types of files in a folder look here:

share|improve this answer
for /F %i IN ('dir /b ^| find /i "." /c') DO if %i EQU 69 echo "the same"
share|improve this answer
How is that a solution to the question? – Oliver Salzburg Feb 4 '13 at 12:27
More explanation of what's going on and why would be useful. – KronoS Feb 4 '13 at 14:52

Your Answer


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.