Computing.Net > Forums > Disk Operating System > count the file numbers in a folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

count the file numbers in a folder

Reply to Message Icon

Name: george (by gp)
Date: May 29, 2008 at 22:26:00 Pacific
OS: xp
CPU/Ram: dell
Product: dell
Comment:

Hi, I want to write a batch file to do:

if "number of files in a directory" gtr 10
( command-1.exe
command-2.exe )

I know to count the file number is
dir /b | find /c /v ""
but how to put it into the above batch commands? pls help. thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 29, 2008 at 23:57:31 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

if not %1'==' set src=%1 && goto :count

set /p src=which directory ?

:count

for /f "tokens=* delims= " %%a in ('dir /b/a-d !src!') do (
set /a C+=1
)

if !C! gtr 10 (
echo there are !C! files
echo do command1
) else (
echo there are !C! files; nothing done
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: george (by gp)
Date: May 30, 2008 at 00:26:19 Pacific
Reply:

Thanks and it works.
However is there any simpler lines doing the job? similar like

if ('dir /b | find /c /v "" !src!') gtr 10
( do command1
do command2)

instead of your for-looping all files in the directory?

Thanks again.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: count the file numbers in a folder

if a folder with the word www.computing.net/answers/dos/if-a-folder-with-the-word-/13865.html

Count line in a text file www.computing.net/answers/dos/count-line-in-a-text-file/14001.html

show the port numbers in use www.computing.net/answers/dos/show-the-port-numbers-in-use/4634.html