Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

First you make list of folders, then:
::=======================
@echo off
setLocal EnableDelayedExpansionfor /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

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

Either will do
=====================================
If at first you don't succeed, you're about average.M2

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.Countsave the above as script.vbs and on command line:
c:\test> cscript /nologo script.vbsFor more folders, just add similar code

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

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

I THINK MY QUESTION HAS BEEN STOPPED FOR A MOMENT HEHE... STILL WAITING ?
K2™
System/Network Engineer

![]() |
![]() |
![]() |

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