简体   繁体   中英

Set Directory listing as variable in batch file dir /B /A-D /S | find /c /v “~~~”

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:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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