2016-12-14 151 views
0

我的批處理程序確實顯示了所需文件夾的大小,但未顯示包括子文件夾在內的子文件夾的大小,文件夾。它只是跳過它們。如何讓程序查看文件夾的總大小?批處理文件顯示文件夾大小,但不顯示該子文件夾中子文件夾和子文件夾的大小

計劃在這裏:

@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 

在此先感謝!

Niels

回答

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 
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 /?

相關問題