0

This is an attempt at sorting unknown files into unknown directories by listing each directory's content into a list (placed in each directory). A single new file %filename% is divided into words (by spaces) and those words are used to search the file databases keywords.txt in each directory. I am supposed to count these hits together to figure out where the file belongs, but my counting system does not work at all.

set "count="
:: feed a list of all subdirectories
for /f "delims=" %%i in ('dir /s /b /a:d') do (
    rem reset keywords, then rebuild 
    echo. >"%%~i\keywords.txt" & for /f "delims=" %%a in ('dir "%%~i\*.*" /b /a:-d') do echo %%~na >>"%%~i\keywords.txt"
    @echo on
    for %%a in (%filename%) do find /i /c "%%a" "%%~i\keywords.txt" && set count+=1
    @echo off
    echo count is %count%
)

one clue might be that the last line produces no %count%, just count is

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Bricktop
  • 533
  • 3
  • 22

1 Answers1

1
for %%a in (%filename%) do find /i /c "%%a" "%%~i\keywords.txt" && set /A count+=1
@echo off
CALL echo count is %%count%%

The /A in the set command invokes arithmetic mode; your code would have simply set the variable count+ to the value 1.

The call invokes a subshell which reports the required value. There must be thousands of SO articles on this issue. Try searching for delayed expansion.

Magoo
  • 77,302
  • 8
  • 62
  • 84