Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to handle bat that counts the number and total size of all files in a folder

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces how to deal with the bat of the number and total size of all files in the statistical folder, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Recently, my computer does not know why the disk space will slowly become smaller, and after a period of time, two or three GB of space will be released. I want to monitor and see if the files generated under that folder occupy my storage space. I want to monitor by layer and finally find out the reason.

From the Internet to find a command line to display the size of the specified folder directory batch program, but found that it is not very satisfactory, always feel that it is not very suitable for my use

The first program, can display the file size under a folder, but I want to display by layer, but can not meet my requirements, the procedure is as follows:

Echo offecho.set / p dirPath=please input folder path:set / as = 1024*1024*1024for / f "tokens=3 delims="% I in ('dir / s / a /-c "% dirPath%" ^ | findstr files') do (set z%% I) echo.echo folder:% dirPath%set d=bitif% z% gtr 1024 set / a "z > > = 10" & set d=KBif% z% gtr 1024 set / a "z > > = 10" & set d=MBif% z% gtr 1024 set / a "z > > = 10" & the total size of set d=GBecho is: Z d%&echo.if z LSS s echo this folder content is less than 1Gpause > nul

For the second program, you can display the hierarchical directory under the current folder, but do not loop the size of the folder each time, the procedure is as follows:

Echo offsetlocal enabledelayedexpansion (for / d% an in (C:\ KuGou\ *) do (set/a n=z=0 pushd "% a" for% b in (*. *.) Do (set/a nymphs) set/a "z > > = 20" popd echo;%%a [! n! ) > Statistical results .txtpause

Through the above two programs, I have integrated and intend to synthesize a program, which should be about the same as the program I need. Just do it. Let's take a look at my program:

@ echo offsetlocal enabledelayedexpansionecho.set / p dirPath=please input folder path:echo% dirPath%echo.for / d% an in (% dirPath%\ *) do (set/a zz=0 for / f "tokens=3 delims="% t in ('dir / s / a /-c "% a" ^ | findstr files') do (set zz=%%t) set d=bitif! zz! GEQ 1024 set / a "z1roomroomzz! > > 10" & set d=KBif! Z1! GEQ 1024 set / a "z2chocolate Z1! > > 10" & set d=KBif! Z2! GEQ 1024 set/a "z3roomroomz2! > 10" & set d=KBecho folder:% a, size:! Z3roomGB =! Z2roomMB =! Z1roomroomd!) for / f "tokens=1-4 delims="% I in ('dir / a /-c% dirPath% ^ | findstr files') do (set/a ss=%%k set/a ss > > = 10if! ss! GEQ 1024 set / a "s _ 1s > > 10" & set d=KB if! s _ 1! GEQ 1024 set / a "s 2s 1! > 10" & set d=KB if! s 2! GEQ 1024 set / a "s3roomroomrooms2! > 10" & set d=KB echo has% I% j under the "% dirPath%" root directory, with a total size of:! s3roomGB =! s2roomroomMB =! s1roomroomd!) pause

Code 4: after execution, the statistical folder contains all the files and all the files under the subfolder, as well as the files under the subfolder and the files under the subfolder

@ echo offsetlocal enabledelayedexpansion (for / f "delims="% I in ('dir / fsi') do (cd "% ~ fsi" set/a delims= 0 for / f "delims="%% an in ('dir / bAccord lash AAA') do (set/an axioms 1 recording nomenclature% Uniza 2 > nul) set/a n/=1048576echo.%%~fi:! a!:! nagram MB) > statistical results .txtpause

MB does not support decimal places. If the file is too small, it will be displayed as zero and can be deleted.

Set/a nUniverse 1048576

And delete MB and change it to bytes.

Or use KB and change it to

Set/a n/=1024echo.%%~fi:! a!:! n!KB

Code 5: pure batch processing is limited in numerical computation, but it is simple to combine batch processing with awk:

Need to drag and drop the execution

# & cls & (for / f "delims="% an 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 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: https://www.yisu.com/softs/515570.html

The program does not explain much, we can see at a glance, just put other people's things together, call the method:

One: double-click to execute and enter the folder path you need to build according to the prompts.

Second: start-- run-- cmd, then find the place to store the bat file, and directly enter the bat file name to execute.

Three: you can also directly output to the file, for example: C:\ > f3.bat > 111.txt enter after you can only see the cursor flash, then you can directly enter the folder path.

Description: if output to a file form, the last pause line of the code (pause code) is deleted, so that after the program execution will automatically exit, will not stay in the program all the time.

The bat on how to deal with the number and total size of all files in the statistical folder is shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report