2

With Windows XP and Windows 7 batch file ...

With a one (1) line batch output, How to show total bytes in
current folder and all sub folders?

dir /s does output the desired number of bytes near the bottom of the output.

How to output that information? Like

1234567890 bytes

Here are 6 examples of what is working in a batch.
We have 2 methods showing 3 results each:

"d:\temp2" folders (-system -hidden) = 5921  
"d:\temp2" folders (+system +hidden) = 5926  
"d:\temp2" files ................... = 42792  


"d:\temp2" folders (-system -hidden) = 5921  
"d:\temp2" folders (+system +hidden) = 5926  
"d:\temp2" files ................... = 42792  

The above question is asking how to output with batch

"d:\temp2" bytes .................., = 1234567890  

The 6 working batch file commands are:

First 3 are one line commands

echo One line command outputs  

1

echo echo | set /p dummyName=""d:\temp2" folders (-system -hidden) = " && (dir /s /b /ad-s-h "d:\temp2" |find /c /v "")  

2

echo echo | set /p dummyName=""d:\temp2" folders (+system +hidden) = " && (dir /s /b /ad     "d:\temp2" |find /c /v "")  

3

echo echo | set /p dummyName=""d:\temp2" files                     = " && (dir /s /b /ad-d   "d:\temp2" |find /c /v "")  

4

set count=   
for /f %%a in ('dir /s /b /ad-s-h "d:\temp2" ^|find /c /v "" ') do set count=%%a  
echo "d:\temp2" folders (-system -hidden) = %count%   

5

set count=   
for /f %%a in ('dir /s /b /ad     "d:\temp2" ^|find /c /v "" ') do set count=%%a  
echo "d:\temp2" folders (+system +hidden) = %count%   

6

set count=   
for /f %%a in ('dir /s /b /a-d    "d:\temp2" ^|find /c /v "" ') do set count=%%a  
echo "d:\temp2" files                     = %count%   

With a one (1) line batch output, How to show total bytes in
current folder and all sub folders?

--

  • 1
    Edit your question and indent code with 4 spaces, please. – jftuga Oct 22 '17 at 1:50
0
@echo off
setlocal

set DNAME=D:\temp2

for /f "usebackq tokens=1,2,3,4" %%a in (`dir %DNAME% /s/w/-c ^| findstr "File(s)"`) do set BYTES=%%c
echo %BYTES% bytes

This outputs total number of bytes for d:\temp2 and its subdirectories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.