标题: [文件操作] [分享]批处理获得某目录下的一级子目录的大小 [打印本页]
作者: hfg1977 时间: 2011-3-28 17:46 标题: [分享]批处理获得某目录下的一级子目录的大小
我用于查看与清理c:盘- @echo off
- set "ret_fname=%~dp1.\%~n1.txt"
- goto start
- :help
- echo.===== Ver: 1.0 =========================== 发布日期: 2011-03-16 =======
- echo. BAT_NAME: GetDirSize.bat
- echo. 返回值: %ret_fname%
- echo. 作用 : 获得某目录下的一级子目录的大小
- echo.====================== Copyright@ by hf-g 2011-03-16 [彭城] ===========
- ping /n 4 127.1>nul
- goto:end
- :start ============================================================
- if /i "%~1"=="" goto help
- if /i "%~1"=="-?" goto help
- setlocal enabledelayedexpansion&chcp 437>nul
- set "fname=%~1"
- ::=======================MAIN==============================
- set/a count=0
- for /f "delims=" %%A in ('dir "%~1" /ad/b') do (
- set "_!count!=%%~A"
- for /f "delims=" %%l in ('dir "%~1.\%%~A" /a-d /s ^| findstr /i "\<File.*bytes$"') do (
- set _!count!_size=%%l
- for /f %%a in ("!count!") do (set "_!count!_size=!_%%a_size:*)=!")
- )
- set/a count+=1
- )
-
- set/a count-=1
- cd.>"%ret_fname%"
- echo.%~dp1.\%~n1下的一级子目录的大小:>>"%ret_fname%"
- echo.>>"%ret_fname%"
-
- for /l %%a in (0,1,!count!) do (
- if "!_%%a_size!"=="" set "_%%a_size= "
- echo !_%%a_size! !_%%a!>>"%ret_fname%")
-
- start "" "%ret_fname%"
- :end ==============================================================
- exit/b
复制代码
效果如下:- C:\.\Program Files下的一级子目录的大小:
-
- 48,922,170 bytes Common Files
- 758,784 bytes Windows NT
- 250,216 bytes Windows Media Player
- Internet Explorer
- Outlook Express
- WindowsUpdate
- microsoft frontpage
- msn gaming zone
- netmeeting
- movie maker
- xerox
- 974,067 bytes Renesas Electronics
- 21,320,828 bytes InstallShield Installation Information
- 3,003,047 bytes Realtek
- 37,724,417 bytes Reference Assemblies
- 25,757 bytes MSBuild
- 1,591,896 bytes OpenAL
- 11,715,619 bytes Microsoft Games for Windows - LIVE
- 67,591,512 bytes ATI Technologies
- 77,295,807 bytes NVIDIA Corporation
- 5,500,928 bytes GridService
- 5,774,950 bytes Audio Deck
复制代码
- C:\.\下的一级子目录的大小:
-
- 1,563,057,560 bytes WINDOWS
- 282,449,998 bytes Program Files
- argh.
- 9,276,089 bytes ados
- 85 bytes Recycled
- 141,203 bytes temp
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |