FOR / R - 使用set / A [变量] = [变量] + %%〜ZA [英] FOR /R - Using set /a [variable] = [variable] + %%~zA

查看:633
本文介绍了FOR / R - 使用set / A [变量] = [变量] + %%〜ZA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有循环命令和一个目录下的一个特定的扩展和所有子目录设置每个文件的文件大小:

I've got a command to loop and set the file size of each file with a specific extension under a directory and all subdirectories:

FOR /R "C:\Users" %%G IN (*.*) do set /a size = %size% + %%~zG

我想该命令使用%大小%+ %%!ZG循环的时候,但是当我运行该批处理文件,输出不断有大小%%设置为0。我想有所有的文件被搜索的大小加起来,不能仅仅停留0在最后会发生什么,为%size%被设置为最后文件扫描。

I would like the command to use the %size% + %%!zG when looping, but when I run the batch file, the output constantly has "%size%" set to 0. I want to have all the file sizes that are searched to add up, not just stay 0. What happens at the very end, is %size% is set to the very last file "scanned".

出于某种原因,它说:0不断,并没有加起来每一个循环。谢谢!所有答复都AP preciated。

For some reason it says "0" constantly and it doesn't add up each "loop". THank you! All responses are appreciated.

推荐答案

试试这个:

setlocal enabledelayedexpansion
FOR /R "C:\Users" %%G IN (*.*) do set /a size = !size! + %%~zG

在for循环,你不能引用环境变量正常。

In for loops you can not refer to environment variables normally.

刚刚意识到我们使用设置/ A !!!!!!!

Just realised we were using set /a !!!!!!!

FOR /R "C:\Users" %%G IN (*.*) do set /a size+=%%~zG

好多做这件事的方式。

Much better way of doing it.

这篇关于FOR / R - 使用set / A [变量] = [变量] + %%〜ZA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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