1.

Solve : Counting a selected number of files with specific names in a folder?

Answer»

Hello
I have a bunch of files in a folder that their names COME from a text file (list.txt). My text file looks like this
abc , yes
def , yes
ghi, no
jkl, yes
I need to read every line of this text file and if the second part ( after COMMA) is "yes" pick the first part and count all my files that include that name in specific folder.
My files in my folder look like this
file.abc.1.txt, file.abc.8.txt, file.def.1. txt,....
so my result should be 2 for abc and 1 for def

I tried with this batch file
for /F "tokens=1-2 delims=," %%a in (c:\users\aaa\desktop\project\list.txt) do (
echo b: %%b
echo a: %%a
if %%b==yes (
set count=0
set pattern=file.%%a%.?.txt
echo file.%%a%.?.txt
for /f %%i in ('dir /b /a-d %pattern% ^| find /c /v ""') do @call set count=%%i
echo count: %count%
)
)

But when I run it this is what I get



C:\Users\aaa\Desktop\Project>(
echo b: no
echo a: abc
if yes == yes (
set count=0
set pattern=file.abc.?.txt
echo file.abc.?.txt
)
)


so basically it does not replace numbers with "?" and does not CONTINUE to count the file.abc files.
Any idea ?

ThanksYou need to use delayed EXPANSION.



Discussion

No Comment Found