China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 09:30
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Calculate the size of each directory View 997 Replies 4
Original Poster Posted 2008-07-29 17:53 ·  中国 四川 成都 电信
初级用户
★★
Credits 159
Posts 56
Joined 2006-09-15 10:31
19-year member
UID 62663
Status Offline
There are many directories inside d:\aaa on my computer, for example 111 222 333, and inside each directory there are many subdirectories and files. I want to calculate the sizes of these directories like 111 222 333. How should I write it?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
+1 2008-07-31 10:32
Floor 2 Posted 2008-07-30 01:06 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /ad /b "d:\aaa"') do (
for /f "delims=" %%i in ('dir /s /a-d/b "%%a\*.*"') do set /a n+=%%~zi
echo total file size in %%a is !n! bytes
  set "n=0"
)
pause>nul


[ Last edited by bat-zw on 2008-7-30 at 01:13 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
zhoumeng +1 2008-07-31 09:43
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-07-30 12:43 ·  中国 四川 成都 电信
初级用户
★★
Credits 159
Posts 56
Joined 2006-09-15 10:31
19-year member
UID 62663
Status Offline
Thank you very much, I learned quite a lot.
Floor 4 Posted 2008-07-31 09:43 ·  中国 广东 深圳 电信
初级用户
Credits 34
Posts 7
Joined 2008-07-30 20:27
18-year member
UID 122420
Gender Male
Status Offline
Why didn't I think of that? For a single directory, size is a whole.
For a large directory, then the sizes of the small directories inside can be calculated.
But could you modify it so the unit is KB, and put a comma every three digits?
Floor 5 Posted 2008-08-03 02:05 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
@echo off&setlocal enabledelayedexpansion
for /r /d %%a in (*) do (
for %%i in ("%%a\*.*") do set/a n+=%%~zi
set/a kb=n/1024
call :lp "%%a"
echo.&set n=0
)
pause>nul&exit/b

:lp
if defined kb (
set var=,!kb:~-3!
set size=!var!!size!
set kb=!kb:~,-3!
goto lp
)
set size=!size:~1!
echo about !size!KB in %~1
set size=



Converted to KB.
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Forum Jump: