How to check the count of .txt files in a folder (dir command)?

All we need is an easy explanation of the problem, so here it is.

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

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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.

Method 2

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.

Method 3

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

Method 4

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

Method 5

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

CD %UserProfile%\Desktop
DIR *.txt | FIND /c /i ".txt"

Method 6

for /F %i IN ('dir /b ^| find /i "." /c') DO if %i EQU 69 echo "the same"

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply