将目录列表设置为批量文件目录目录目录目录/B /A-D /S |查找/c /v“~~~”

时间:2021-06-09 23:21:07

I am trying to write a bat file that counts all files in a directory and subdirectoires and sets a variable based on the output. Something like this:

我正在编写一个bat文件,它计算目录和子目录中的所有文件,并根据输出设置一个变量。是这样的:

set /a FILECOUNT=dir c:\Dir1 /B /A-D /S | find /c /v "~~~"
echo %FILECOUNT%

The output of the dir is only a number, I can't figure out how to get that number into my variable.

dir的输出只是一个数字,我不知道如何将这个数字放到我的变量中。

1 个解决方案

#1


2  

for /f %%a in ('dir c:\Dir1 /B /A-D /S | find /c /v "~~~"') do set FileCount=%%a

#1


2  

for /f %%a in ('dir c:\Dir1 /B /A-D /S | find /c /v "~~~"') do set FileCount=%%a