My computer recently didn't know why the disk space will slowly become smaller, and after a period of time, there will be two or three GB of space to be released, using I want to monitor, look at the file generated under that folder to occupy my storage space, I want to monitor the layer, and finally find out why.
From the Internet to find a command line to display the size of the specified folder directory batch program, but the discovery is not very satisfactory, the total feeling is not very suitable for my use;
The first program, you can display the size of a file under a folder, but I want to display by layer, but not meet my requirements, the program is as follows:
@echo off
Echo.
set/p dirpath=please Input Folder path:
set/a s=1024*1024*1024
for/f "tokens=3 delims="%%i in (' dir/s/a/-c "%dirpath%" ^|findstr file) do (set z=%%i)
echo.
echo folder:%dirpath%
set D=bit
if%z% gtr 1024 set/a "z>>=10" &set d=kb
if%z% gtr 1024 set/a "z>& gt;=10 "&set d=mb
if%z% gtr 1024 set/a" z>>=10 "&set D=GB the
total size of ECHO is:%z%%d%&echo.
If%z% LSS%s% echo the folder content is less than 1G
Pause>nul
The second program, can display the current folder under the level directory, but do not cycle every time the size of the folder, the program is as follows:
@echo off
setlocal enabledelayedexpansion
(for/d%%a in (c:\kugou\*) do (
set/a n=z=0 pushd
"%%a"
For%%b in (*.*.) Do (
set/a n+=1,z+=%%~zb
)
set/a "z>>=20"
popd
[echo;%%a!n! M])
> Statistical results. txt
Pause
Through the above two programs, I integrated a bit, intend to synthesize a program, should be the same as I need the program, say dry, the following look at my program:
@echo off
setlocal enabledelayedexpansion
echo.
set/p dirpath=please Input Folder path:
echo%dirpath%
echo.
FOR/D%%a in (%dirpath%\*) does (
set/a zz=0 for/f "
tokens=3 delims="%%t in (' dir/s/a/-c "%%a" ^|findstr Files " Do (
set zz=%%t
)
set d=bit
if!zz! GEQ 1024 set/a "z1=!zz!>>10" &set d=kb
if!z1! GEQ 1024 set/a "z2=!z1!>>10" &set d=kb
if!z2! GEQ 1024 set/a "z3=!z2!>>10" &set d=kb
Echo folder:%%a, size is:!z3! GB =!z2! MB =!z1!! d!
)
for/f "Tokens=1-4 delims="%%i in (' dir/a/-c-%dirpath% ^|findstr files ') do (set/a ss=%%k set/a ss>>=10
, D=bit
if!ss! GEQ 1024 set/a "s1=!ss!>>10" &set d=kb
if!s1! GEQ 1024 set/a "s2=!s1!>>10" &set d=kb
if!s2! GEQ 1024 set/a "s3=!s2!>>10" &set d=kb
Echo has%dirpath%%%i in the "%%j" root directory, the total size is:!s3! GB =!s2! MB =!s1!! d!
)
Pause
Code four: After implementation statistics folder contains all files and files under all subfolders, as well as files under subfolders of subfolders, and files under subfolders under subfolders
@echo off
setlocal enabledelayedexpansion
(for/f "delims="%%i in (' Dir/s/b/l/ad ') Do (
CD "%%~FSI"
set /a a=0,n=0
for/f "delims="%%a in (' Dir/b/l/aa ') do (
set/a a+=1,n+=%%~za 2>nul
)
set/a />echo.%%~fi:!a! :!n! MB
) > Statistical results. txt
Pause
MB does not support decimal places, the file is too small to show zero, you can delete
set/a n/=1048576
and remove MB to byte.
Or use KB, change to
set/a n/=1024
echo.%%~fi:!a!:!n! Kb
Code 5: Limited to numeric computations with pure batches, the problem with batch processing awk is simple:
Need to drag and drop execution
# & CLS & (for/f "delims="%%a in (' dir/a-d/b/s%1 ') do @echo%%~za) | Gawk-v path=%~n1-f%0 >con & pause & Exit
{sum+=$0}
end{
printf "%s folder Total size is: \n%.2f byte\n%.2f mb\n%.2f gb\n ", path,sum,sum/1024/1024,sum/1024/1024/1024
}
gawk 4.1.0 Download Address: http://www.jb51.net/softs/515570.html
The procedure also does not have many explanations, everybody sees to understand, just puts the other people's thing together, invokes the method:
One: Double click execution, and enter the folder path you need to build according to the prompts.
Two: Start-run--cmd, and then find where to store the bat file, directly enter the bat file name can be executed.
Third: can also be directly output to the file, for example: C:\>f3.bat>111.txt return only to see the cursor Flash flash, when you directly enter the folder path can be.
Note: If the output to the file form, and finally the code last pause line (pause code) deleted, so that when the program after the execution will automatically quit, will not stay in the program.
The above two programs are from the "Batch Home", the address is easy to follow after the following and lookup