Board logo

标题: [文件操作] [分享]批处理获得某目录下的一级子目录的大小 [打印本页]

作者: hfg1977    时间: 2011-3-28 17:46     标题: [分享]批处理获得某目录下的一级子目录的大小

我用于查看与清理c:盘
  1. @echo off
  2. set "ret_fname=%~dp1.\%~n1.txt"
  3. goto start
  4. :help
  5. echo.===== Ver: 1.0 =========================== 发布日期: 2011-03-16 =======
  6. echo. BAT_NAME: GetDirSize.bat
  7. echo. 返回值: %ret_fname%
  8. echo. 作用  : 获得某目录下的一级子目录的大小
  9. echo.====================== Copyright@ by hf-g 2011-03-16 [彭城] ===========
  10. ping /n 4 127.1>nul
  11. goto:end
  12. :start ============================================================
  13. if /i "%~1"=="" goto help
  14. if /i "%~1"=="-?" goto help
  15. setlocal enabledelayedexpansion&chcp 437>nul
  16. set "fname=%~1"
  17. ::=======================MAIN==============================
  18. set/a count=0
  19. for /f "delims=" %%A in ('dir "%~1" /ad/b') do (
  20. set "_!count!=%%~A"
  21. for /f "delims=" %%l in ('dir "%~1.\%%~A" /a-d /s ^| findstr /i "\<File.*bytes$"') do (
  22. set _!count!_size=%%l
  23. for /f %%a in ("!count!") do (set "_!count!_size=!_%%a_size:*)=!")
  24. )
  25. set/a count+=1
  26. )
  27. set/a count-=1
  28. cd.>"%ret_fname%"
  29. echo.%~dp1.\%~n1下的一级子目录的大小:>>"%ret_fname%"
  30. echo.>>"%ret_fname%"
  31. for /l %%a in (0,1,!count!) do (
  32. if "!_%%a_size!"=="" set "_%%a_size= "
  33. echo !_%%a_size! !_%%a!>>"%ret_fname%")
  34. start "" "%ret_fname%"
  35. :end ==============================================================
  36. exit/b
复制代码
效果如下:
  1. C:\.\Program Files下的一级子目录的大小:
  2.      48,922,170 bytes Common Files
  3.         758,784 bytes Windows NT
  4.         250,216 bytes Windows Media Player
  5. Internet Explorer
  6. Outlook Express
  7. WindowsUpdate
  8. microsoft frontpage
  9. msn gaming zone
  10. netmeeting
  11. movie maker
  12. xerox
  13.         974,067 bytes Renesas Electronics
  14.      21,320,828 bytes InstallShield Installation Information
  15.       3,003,047 bytes Realtek
  16.      37,724,417 bytes Reference Assemblies
  17.          25,757 bytes MSBuild
  18.       1,591,896 bytes OpenAL
  19.      11,715,619 bytes Microsoft Games for Windows - LIVE
  20.      67,591,512 bytes ATI Technologies
  21.      77,295,807 bytes NVIDIA Corporation
  22.       5,500,928 bytes GridService
  23.       5,774,950 bytes Audio Deck
复制代码
  1. C:\.\下的一级子目录的大小:
  2.   1,563,057,560 bytes WINDOWS
  3.     282,449,998 bytes Program Files
  4. argh.
  5.       9,276,089 bytes ados
  6.              85 bytes Recycled
  7.         141,203 bytes temp
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2