Skip to content

Instantly share code, notes, and snippets.

@jorben
Created October 16, 2016 08:24
Show Gist options
  • Save jorben/c08010a6f887946fd8f0ecd2fa24d5b0 to your computer and use it in GitHub Desktop.
Save jorben/c08010a6f887946fd8f0ecd2fa24d5b0 to your computer and use it in GitHub Desktop.
windws 下统计指定目标路径下各文件夹的大小
@echo off
IF [%1]==[] GOTO USAGE
if NOT exist "%1" (ECHO "%1" path not exist & GOTO END)
:DIR_PATH
dir /ad /b %1 > 1.txt
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (1.txt) do (
rem echo
dir /s "%1\%%i" |findstr 个文件 > 2.txt || echo. > 2.txt
rem for /f "eol=0 tokens=1,3 " %%j in (2.txt) do set ll=%%k 字节 %1\%%i %%j 个文件
for /f "eol=0 tokens=1,3 " %%j in (2.txt) do set ll=%%k & set ll=!ll:~0,-9! M %1\%%i %%j 个文件
echo !ll!
rem echo.
)
set total=
Endlocal
del 1.txt 2.txt
GOTO END
:USAGE
echo Usage: %0 dir_path
GOTO END
:END
rem pause
@jorben
Copy link
Author

jorben commented Oct 16, 2016

使用举例: 计算C盘Windows目录下各文件夹的大小
拷贝 win_dush.bat到C盘
执行 win_dush.bat Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment