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

counting files in sub directories

Reply to Message Icon

Original Message
Name: alwaysk2
Date: August 8, 2008 at 11:31:24 Pacific
Subject: counting files in sub directories
OS: windows 2000 server
CPU/Ram: INTEL 8 GB RAM
Model/Manufacturer: 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


Report Offensive Message For Removal


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

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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

Either will do


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

M2


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal


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

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


Report Offensive Follow Up For Removal

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

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

K2™
System/Network Engineer


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: counting files in sub directories

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge