简体   繁体   English

将命令的输出设置为变量

[英]Set output of a command to a variable

I want to get the number of files modified before 10 days to a variable. 我想获取在10天前修改为一个变量的文件数。 I can get number of files using 我可以使用获取文件数量

forfiles /P "D:\files" /S /D -10  | find /c /v ""

But when i try to assign it to a variable using FOR it gives error. 但是,当我尝试使用FOR将其分配给变量时,会出现错误。 Command I used in FOR is 我在FOR中使用的命令是

FOR /F "delims=" %i IN ('forfiles /P "D:\files" /S /D -10  | find /c /v ""') DO set today=%i

It actually works fine when I remove | find /c /v "" 实际上,当我删除| find /c /v "" | find /c /v ""

FOR /F "delims=" %i IN ('forfiles /P "D:\files" /S /D -10  ^| find /c /v ""') DO set today=%i

在这种情况下,您需要使管道逸出。

Yes you can use the FIND command to count how many occurrences it finds but you don't need to. 是的,您可以使用FIND命令来计算发现的次数,但是您不需要。 You could just use the set command to iterate a variable. 您可以只使用set命令来迭代变量。

FOR /F "delims=" %%G IN ('forfiles /P "D:\files" /S /D -10') do @set /a count+=1 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM