count no of files in a directory

March 20, 2009 at 14:06:18
Specs: Windows 2000
Hi ,

I am using the following command in my batch file to find no of batch files in a directory
dir "a\b\c" | find /v /c "::"

I am able to get the count,but i dont know whow to store it in a variable.

I want to store the count in a variable and use that variable in rest of my batch file code.

See More: count no of files in a directory

Report •

March 20, 2009 at 14:31:02
Before I start to post the code you requested let me point out aome issues about your DIR statement (dir /A /B /C).

1- The /C switch is absolutely useless in that context and more it is set by default.
2- If you code /A without specifying any modifier your count takes into account the directories and the hidden/system files too. To get just the number of your standard files /A-D-H must be coded.

So stated the following statement to be coded inside a batch file sets a variable (Count) to the files' number:

for /F %%j in ('dir /A-D-H /B ^| find /C /V ""') do set Count=%%j

Be aware the variable can be referred by other statements inside the same batch, i.e. in other words it is not persistent. This is however far beyond this quick tutorial.

Report •

March 23, 2009 at 12:27:38
Thankyou very much for your reply,
I am very new to this stuff,I am sorry for bothering more on this.

My folder is C:\Subhash\Test\Log.

so what should i code in my batch file ??

The below command is giving error:
for /F %%j in ('dir C:\Subhash\Test\Log ^| find /C /V ""') do set Count=%%j

Please kindly correct the command.

Report •

March 23, 2009 at 12:29:42
Alos one more request i want the file count in the above given folder,but i dont want the sub folder file count.

Report •

Related Solutions

March 24, 2009 at 06:31:10
Could any body please help me on this......

I have to search count of files in a folder C:\Log\Staging

I am using the below command in my batch file :
for /F %%j in (`dir /A-D-H C:\Log\Staging^ | find /C /V "::"') do set Count=%%j

but it is throwing an error as :
| was unexpected at this time

My complete bat file looks like :

CD Oracle\bin


for /F %%j in (`dir /A-D-H C:\Log\Staging^ | find /C /V "::"') do set Count=%%j

IF (%count% != 1) echo successful

please kindly anyone help me on this.I am very new to this one and couldnot able to resolve this issue from past few days.

Appreciate your help in advance!!!

Report •

Ask Question