我正在开发一个程序,以查找几个文件夹的文件大小,并显示它们相对于总可用文件夹的百分比。这是我的代码。
@echo off
setLocal EnableDelayedExpansion
set item=0
set total=0
cd..
cd..
cd..
cd..
echo In location %cd%
cd folder1
call :size
cd..
cd folder2
call :size
cd..
cd folder3
call :size
cd..
cd folder4
call :size
cd..
echo.
echo.
echo Compared to total used:
echo total: !total!
echo.
set /A int1=100*!person1! / !total!
echo 1: !int1! percent
set /A int2=100*!person2! / !total!
echo 2: !int2! percent
set /A int3=100*!person3! / !total!
echo 3: !int3! percent
set /A int4=100*!person4! / !total!
echo 4: !int4! percent
echo.
echo.
echo Compared to total available:
这是问题
set total=275000
echo total: !total!
echo.
set /A int1=100*!person1! / !total!
echo 1: !int1! percent
set /A int2=100*!person2! / !total!
echo 2: !int2! percent
set /A int3=100*!person3! / !total!
echo 3: !int3! percent
set /A int4=100*!person4! / !total!
echo 4: !int4! percent`
pause >nul
exit
:size
set /a item=%item%+1
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI/1024
set /a sum=!sum!+!value!
)
echo.
@echo %CD%:!sum! k
set person!item!=!sum!
set /a total=!total!+!sum!
goto :EOF
我遇到的问题是与总可用部分相比。我可以使用已用空间的百分比,但是在获取允许的文件夹最大总空间中所占的百分比时遇到了麻烦。我收到了一些本不应超过100%的疯狂数字。