Computing.Net > Forums > Programming > Count files in a directory

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 files in a directory

Reply to Message Icon

Name: amritag
Date: March 3, 2005 at 19:03:09 Pacific
OS: Windows 2000
CPU/Ram: 256MB RAM
Comment:

I need to count the number of files in a directory. I used the following DOS Prompts--

Go to respective folder--

Set Count=0
.......
Dir *
If not ErrorLevel 1 Set /A Count=%Count%+1
.......
Echo %Count% Files found.

But this is not working. Can someone please help.

Thanks in advance,
Amrita




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 3, 2005 at 22:00:15 Pacific
Reply:

Hi Amrita,

Try this:

::**
dir /a-d | find /c ":" > NUMfiles.###
set /p count=<NUMfiles.###
::**

This assumes that your 'file time' layout contains a ":", like this:

03-03-2005 23:27 87 CHU2.BAT

***
HTH


M2


0

Response Number 2
Name: amritag
Date: March 4, 2005 at 01:15:52 Pacific
Reply:

Thanks for the solution.
I was looking for excel files in thwe directory, so I modified the code as follows:

dir /a-d | find /c ".xls" > NUMfiles.###
set /p count=<NUMfiles.###
Echo %count% > count.txt

This is working fine.

Thanks a ton


0

Response Number 3
Name: Mechanix2Go
Date: March 4, 2005 at 01:23:51 Pacific
Reply:

Hi Amrita,

Glad it's working.

It always cheers me on when someone figures out how to alter the script to suit their needs.

Gives you a sense of self-reliance.

Best

M2


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 Programming Forum Home


Sponsored links

Ads by Google


Results for: Count files in a directory

count no of files in a directory www.computing.net/answers/programming/count-no-of-files-in-a-directory/18316.html

counting files in sub directories www.computing.net/answers/programming/counting-files-in-sub-directories/16810.html

batch to count files in DIR then send email www.computing.net/answers/programming/batch-to-count-files-in-dir-then-send-email/19628.html