Computing.Net > Forums > Programming > counting files in sub directories

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.

counting files in sub directories

Reply to Message Icon

Name: alwaysk2
Date: August 8, 2008 at 11:31:24 Pacific
OS: windows 2000 server
CPU/Ram: INTEL 8 GB RAM
Product: HP
Comment:

Hi,

i am making a batch file and in that one task i need to follow that is to count file in a single folder and count files in 5 different folders.

i have found out the command which gives me a count number of a single folder which is as follows:

dir /s c:\*.* |find /c /v ""
for directories also
dir /s /D c:\*.* |find /c /v ""

but i m not able to make it work on 5 different folders as i want to count total files which are in 5 different folders it will just show me total number of count specifying 5 different folders have these many total number of files thats it....

any ideas... ?

K2™
System/Network Engineer



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 8, 2008 at 12:01:12 Pacific
Reply:

First you make list of folders, then:

::=======================
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%f in (mylist) do (
pushd %%f
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set /a N+=1
popd
)
)
echo !N!


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

M2


0

Response Number 2
Name: alwaysk2
Date: August 8, 2008 at 17:45:28 Pacific
Reply:

what kind of list you are telling me dear, do i have to make a list of folders in a text file having PATH of all the 5 folders? or just need to give paths of all folders where you have written (mylist) in the batch commands.

K2™
System/Network Engineer


0

Response Number 3
Name: Mechanix2Go
Date: August 8, 2008 at 18:00:47 Pacific
Reply:

Either will do


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

M2


0

Response Number 4
Name: ghostdog
Date: August 8, 2008 at 18:25:23 Pacific
Reply:

counting of files are made easy in vbscript. Here's one example

Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder1 = "C:\test1"
strFolder2 = "C:\test2"
Set objFolder1 = objFS.GetFolder(strFolder1)
WScript.Echo objFolder1.Files.Count
Set objFolder2 = objFS.GetFolder(strFolder2)
WScript.Echo objFolder2.Files.Count
WScript.Echo "Total count:" ,objFolder1.Files.Count + objFolder2.Files.Count

save the above as script.vbs and on command line:


c:\test> cscript /nologo script.vbs

For more folders, just add similar code


0

Response Number 5
Name: alwaysk2
Date: August 8, 2008 at 18:25:31 Pacific
Reply:

what i did is i made a mylist.txt file in C: and given the paths of the folders by using COMMAS first but it gave me error mylist.txt is not a recognized command. then i tried editing mylist.txt file and removed commas and just put all the paths in single lines but than also it gave me the same error as stated above. when i am trying to provide the full paths of 5 folders its giving me same error

K2™
System/Network Engineer


0

Related Posts

See More



Response Number 6
Name: alwaysk2
Date: August 8, 2008 at 18:37:47 Pacific
Reply:

thanx a lot for the VBSCRIPT dear but the problem is like the 5 folders daily gets names changed on the DATE like today i will have the folder 08082008 tomorrow i will be having a folder 08092008.. will the script work on that ?

K2™
System/Network Engineer


0

Response Number 7
Name: alwaysk2
Date: August 16, 2008 at 13:15:27 Pacific
Reply:

I THINK MY QUESTION HAS BEEN STOPPED FOR A MOMENT HEHE... STILL WAITING ?

K2™
System/Network Engineer


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: counting files in sub directories

Count files in a directory www.computing.net/answers/programming/count-files-in-a-directory/12308.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

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