I have scripted SizeCnt.bat to determine the size and count of files in a folder, and optionally in all sub-folders.

The syntax for using SizeCnt.bat is:

SizeCnt Folder \[/S\]

where Folder is the path to the folder you wish to measure, and /S is an optional switch that will also include the size and count of the files in all of Folder's sub-folders.

The output is displayed on the CMD console, but you can pipe it to a file using the following syntax:

SizeCnt Folder \[/S\]>FileName

You can import the size and count into environment variables in your script, as in:

for /f "Tokens=1,2" %%s in ('SizeCnt Folder \[/S\]') do set /a FldSize=%%s&set /a fileCnt=%%t

SizeCnt.bat contains:

@echo off
If \{%1\}<h1><a name="_goto_Syntax_set_folder_1#_set_folder_folder_set_folder_folder_#_set_folder_folder_#_if_not_exist_folder_goto_Syntax_if_2_">\{\} goto Syntax
set folder=%1#
set folder=%folder:"=%
set folder=%folder:\#=%
set folder=%folder:#=%
if not exist "%folder%\*.*" goto Syntax
if \{%2\}</a></h1>\{\} goto begin
set xx= %2
set xx=%xx:"=%
if /i "%xx%" NEQ " /s" goto Syntax
set /a cnt=0
set /a tot=0
pushd "%folder%"
call :doit>nul 2>&1
@echo %tot% %cnt%
exit /b 0
for /f  "Tokens=*" %%s in ('dir /b /as /ah /a-d%xx%') do call :addsize "%%s"
goto :EOF
@echo Syntax: SizeCnt Folder \[/S\]
exit /b 1
set /a sz=%~Z1
set /a tot=%tot% + %sz%
set /a cnt=%cnt% + 1