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-12 14:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about dir, asking for advice! View 985 Replies 4
Original Poster Posted 2010-04-12 14:18 ·  中国 上海 电信
新手上路
Credits 8
Posts 8
Joined 2010-04-04 09:00
16-year member
UID 163739
Gender Male
From 四川南充
Status Offline
Experts,
I have a question:

I have many folders in d:\test\, and I want to use a P to view their sizes (the folders).

Thanks!
Floor 2 Posted 2010-04-12 14:50 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Floor 3 Posted 2010-04-12 20:25 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
I'll add one too!!

@echo off
setlocal enabledelayedexpansion
set pt=d:\test
echo :
for /f "tokens=*" %%c in ('dir %pt% /ad /b /s') do (
for /f "tokens=3,4 delims= " %%i in ('dir "%%c"^|findstr "个文件"') do (
echo -------------------
echo."%%c" : %%i %%j
set "zer=%%i"
set "zer=!zer:,=!"
set /a num=!num!+!zer!
)
)
for /f "tokens=3,4 delims= " %%i in ('dir "%pt%"^|findstr "个文件"') do (
echo -------------------
echo."%pt%" : %%i %%j
set "zer=%%i"
set "zer=!zer:,=!"
set /a num=!num!+!zer!
)
echo.
echo :
echo %num% bytes
pause>nul
goto :eof
Floor 4 Posted 2010-04-12 20:46 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
Modified it a bit, now you can calculate the size by dragging in the folder:
@echo off
mode con cols=100 lines=20
setlocal enabledelayedexpansion
set /p pt=Drag in the folder?:
set "pt=%pt:"=%"
echo :
for /f "tokens=*" %%c in ('dir "%pt%" /ad /b /s') do (
for /f "tokens=3,4 delims= " %%i in ('dir "%%c"^|findstr "个文件"') do (
echo -------------------
echo."%%c" : %%i %%j
set "zer=%%i"
set "zer=!zer:,=!"
set /a num=!num!+!zer!
)
)
for /f "tokens=3,4 delims= " %%i in ('dir "%pt%"^|findstr "个文件"') do (
echo -------------------
echo."%pt%" : %%i %%j
set "zer=%%i"
set "zer=!zer:,=!"
set /a num=!num!+!zer!
)
echo.
echo :
echo %num% bytes
pause>nul
goto :eof
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
kennyfan +2 2010-04-13 08:26
Floor 5 Posted 2010-04-17 10:22 ·  中国 上海 电信
新手上路
Credits 8
Posts 8
Joined 2010-04-04 09:00
16-year member
UID 163739
Gender Male
From 四川南充
Status Offline
I don't really understand it, still studying it!!!。


Thanks first!!
Forum Jump: