1、根据 dir 命令的结果获取文件夹大小- @echo off
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- for /f "delims=" %%a in ('dir /b /ad') do (
- for /f "tokens=2 delims=件字" %%b in ('dir /s "%%a" ^| findstr "个文件"') do (
- set "FolderSize=%%b"
- )
- echo %%a: !FolderSize!
- )
- pause
复制代码 2、BAT调用 Windows Sysinternals 工具包里面的 du 命令获取文件夹大小
https://docs.microsoft.com/zh-cn/sysinternals/downloads/du- @echo off
- cd /d "%~dp0"
- for /f "delims=" %%a in ('dir /b /ad') do (
- for /f "tokens=2 delims=:" %%b in ('du -q "%%a" 2^>^&1 ^| findstr "Size:"') do (
- echo %%a: %%b
- )
- )
- pause
复制代码 3、BAT调用PowerShell获取文件夹大小- @echo off
- REM setlocal enabledelayedexpansion
- cd /d "%~dp0"
- for /f "delims=" %%a in ('dir /b /ad') do (
- set /p =%%a: <nul
- powershell -c "(Get-ChildItem -Path '%%a' -Force -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum"
- )
- pause
复制代码 4、批处理统计目录下所有文件夹的大小并把结果转换成KB、MB、GB
http://bbs.bathome.net/thread-31593-1-1.html#pid153139
5、VBS统计文件夹的大小并把结果转换成KB、MB、GB
http://bbs.bathome.net/thread-13307-1-1.html |