7

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

0

6 Answers 6

12
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.

1
  • Is this meant for PowerSheel ? Using the * wildcard seems to only return "File not found"
    – Charles
    Jul 17, 2023 at 9:30
5

You can use the following. Once it has finished you'll see a summary with a count of the total matches:

dir *.txt /w /s
4

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.

1

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:

http://codebyjoshua.blogspot.com/2013/08/find-count-of-files-in-folder-at.html

1

The perfect way to count the .txt files in a folder:

CD %UserProfile%\Desktop
DIR *.txt | FIND /c /i ".txt"
-3
for /F %i IN ('dir /b ^| find /i "." /c') DO if %i EQU 69 echo "the same"
2
  • 3
    How is that a solution to the question? Feb 4, 2013 at 12:27
  • More explanation of what's going on and why would be useful. Feb 4, 2013 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .