I have a folder with many subfolders in it. Each of these subfolders may or may not contain a file named "George.txt".

This command (in a batch file)

for /d %%A in (*) do @if not exist "%%~fA\George.txt*" echo %%~fA

finds all the subfolders where "George.txt" doesn't exist and outputs a list in the cmd window like this:


Now I also need to know the total number of subfolders where "George.txt" doesn't exist. Either by appending numbers to each line:

1. D:\Folder\S1
2. D:\Folder\S5
3. D:\Folder\S11

or displaying a total at the end of the list, I have no preference:

Total: 3

Is something like this possible natively? I'm using Win 7 Ultimate x64.

  • How about counting the output lines? See superuser.com/a/959037/263 Specificallyfind /c can count output lines. – nik Aug 3 at 10:14
  • Sounds good, but how to incorporate it to the command? All I manage to get is "1", "1", "1" every line. – stoyian0v Aug 3 at 10:31

You may try something like this

set /a nCount=0
for /d %%A in (*) do (
  @if not exist "%%~fA\George.txt*" (
    set /a nCount+=1
    echo %%~fA
echo Total %nCount% folder(s) found
  • Great, thank you! – stoyian0v Aug 3 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.