文件夹中存在的文件大小的总和 [英] Sum of size of files present in a folder

查看:97
本文介绍了文件夹中存在的文件大小的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在编写一个批处理脚本来查找目录中存在的文件大小总和,其中包含付款单词



执行以下代码:



set size_slu = 0

for%I in(c: \ Systems\SLU \ *付款* .xml)设置Size_slu + =%〜zI

echo总文件大小:%size_slu%



以上代码只给出了最后一个文件的大小,虽然它在命令提示符下显示了所有单个文件的大小,我怎样才能总结这些大小?



我尝试了什么:



Hi,

I am writing a batch script to find sum of size of files present in a directory which contains payments as a word

On executing below code:

set Size_slu = 0
for %I in (c:\Systems\SLU\*payments*.xml) do set Size_slu+=%~zI
echo total file size :%size_slu%

Above code gives me only the size of the last file although it displays size of all individual files in command prompt, How can I sum up those sizes ?

What I have tried:

set Size_slu = 0
for %I in (c:\Systems\SLU\*payments*.xml) do  set Size_slu+=%~zI
echo total file size :%size_slu%

推荐答案

正如@ Richard-MacCutchan指出的那样,你不能在批处理文件中使用+ =你需要使用长手版本(警告 - 未经测试)
As @Richard-MacCutchan has pointed out, you cannot use += in batch files you need to use the long hand version (caveat - untested)
set Size_slu = 0
set TotSize = 0

for %I in (c:\Systems\SLU\*payments*.xml) do  ( set Size_slu=%~zI
set TotSize=TotSize+Size_slu )

echo total file size :%Tot_slu%

注意括号,因为我将这一行拆分为两行,但以下内容也适用于%$ I

Note the brackets as I've split this over two lines, although the following should also work

for %I in (c:\Systems\SLU\*payments*.xml) do  set Size_slu=Size_slu+%~zI


这篇关于文件夹中存在的文件大小的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆