我的批处理程序确实显示了所需文件夹的大小,但没有显示包含子文件夹的文件夹大小。它只是跳过它们。如何让程序看到文件夹的总大小?
在这里编程:
@echo off &setlocal enabledelayedexpansion
:: folder choose
echo enter desired directory
set /p dir=
cd /d %dir%
::getting folder size
for /f "tokens=3" %%a IN ('dir /a-d /-c') DO (
set size=!free!
set free=%%a
)
echo free space is %free% bytes
echo size is %size% bytes
提前感谢!
尼尔斯
答案 0 :(得分:1)
您只是错过了将/s
选项添加到dir
命令:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "FOLDER=" & set /P FOLDER=""
for /f "tokens=3" %%A in ('
dir /S /A:-D /-C "!FOLDER!"
') do (
set "SIZE=!FREE!"
set "FREE=%%A"
)
echo free space is %free% bytes
echo size is %size% bytes
endlocal
答案 1 :(得分:0)
查看桌面上文件夹的大小。
for /f "skip=2 tokens=3" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Desktop"') do set doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "\/"`) DO @echo %j&echo.
查看System32文件夹的文件夹大小。
for /f "usebackq tokens=2* delims= " %i IN (`dir "%windir%\system32" /a /s ^|findstr /i /v "\/"`) DO @echo %j&echo.
请参阅Findstr /?