Nested DOS For Loop Issues
My goal with this batch file is to quickly find out how many antivirus applications a user has installed. I plan to do this by using two for loops: 

 - Outer loop: Iterate through the folder names in the Program Files directory
 - Inner loop: Iterate through a list of common antivirus names (the AVList variable), looking for matches to the current directory name and appending each match to the AntiVirus variable.

With that said, here's my failing code. The error I'm getting is **"" was unexpected at this time.**. Note that I currently have names of folders in my Program Files in the AVList variable (for testing purposes).

    ::@echo off
    ::variables
    set AntiVirus="Initial Value"
    set AVList=(adobe ccleaner auslogics)
    
    SETLOCAL EnableDelayedExpansion
    
    echo Checking Program Files...
    
    if "%Processor_Architecture%" == "AMD64" (
    echo 64-bit OS
    echo.
    for /d %%f in ("%ProgramFiles(x86)%\*") do (
       echo "%%f"
       SET "folder=%%f"
       REM Begin loop to search substrings with words in AVList
       Call:SearchAV "%folder%"
       )
    ) 
    else echo 32-bit OS
    
    echo.
    echo AntiVirus: %AntiVirus%
    echo.
    
    for /d %%g in ("%ProgramFiles%\*") do (
       echo "%%g"
       SET "folder=%%g"
       REM Begin loop to search substrings with words in AVList
       Call:SearchAV "%folder%"
       )
    )
    
    :SearchAV
    for %%v in ("%AVList%") do (
      echo "%%v"
      SET "av=%%v"
      if /I NOT "!~1:av=!"=="!~1!" set AntiVirus="%AntiVirus%%av%"
     )
    GOTO:EOF
    
    echo.
    echo.
    echo %AntiVirus% found
    echo.
    echo Script created by Matthew Ammann, revised by Andriy M from StackOverflow
    
    @pause

Here's the output redirected to a logfile:


    C:\AVFinder>set AntiVirus="Initial Value" 
    
    C:\AVFinder>set AVList=(adobe ccleaner auslogics) 
    
    C:\AVFinder>SETLOCAL EnableDelayedExpansion 
    
    C:\AVFinder>echo Checking Program Files... 
    Checking Program Files...
    
    C:\AVFinder>if "AMD64" == "AMD64" (
    echo 64-bit OS  
     echo. 
     for / %f in ("C:\Program Files (x86)\*") do (
    echo "%f"  
     SET "folder=%f"  
     REM Begin loop to search substrings with words in AVList  
     Call:SearchAV "C:\Program Files (x86)\Adobe" 
    ) 
    ) 
    64-bit OS
    
    
    C:\AVFinder>(
    echo "C:\Program Files (x86)\Adobe"  
     SET "folder=C:\Program Files (x86)\Adobe"  
     REM Begin loop to search substrings with words in AVList  
     Call:SearchAV "C:\Program Files (x86)\Adobe" 
    ) 
    "C:\Program Files (x86)\Adobe"
    "" was unexpected at this time.
    
    C:\AVFinder>  if /I NOT "!~1:av=!"=="!~1!" set AntiVirus=""Initial Value""(adobe ccleaner auslogics)""


Where am I going wrong?
Nested DOS For Loop Issues
===

My goal with this batch file is to quickly find out how many antivirus applications a user has installed. I plan to do this by using two for loops: 

 - Outer loop: Iterate through the folder names in the Program Files directory
 - Inner loop: Iterate through a list of common antivirus names (the AVList variable), looking for matches to the current directory name and appending each match to the AntiVirus variable.

With that said, here's my failing code. The error I'm getting is **"" was unexpected at this time.**. Note that I currently have names of folders in my Program Files in the AVList variable (for testing purposes).

    ::@echo off
    ::variables
    set AntiVirus="Initial Value"
    set AVList=(adobe ccleaner auslogics)
    
    SETLOCAL EnableDelayedExpansion
    
    echo Checking Program Files...
    
    if "%Processor_Architecture%" == "AMD64" (
    echo 64-bit OS
    echo.
    for /d %%f in ("%ProgramFiles(x86)%\*") do (
       echo "%%f"
       SET "folder=%%f"
       REM Begin loop to search substrings with words in AVList
       Call:SearchAV "%folder%"
       )
    ) 
    else echo 32-bit OS
    
    echo.
    echo AntiVirus: %AntiVirus%
    echo.
    
    for /d %%g in ("%ProgramFiles%\*") do (
       echo "%%g"
       SET "folder=%%g"
       REM Begin loop to search substrings with words in AVList
       Call:SearchAV "%folder%"
       )
    )
    
    :SearchAV
    for %%v in ("%AVList%") do (
      echo "%%v"
      SET "av=%%v"
      if /I NOT "!~1:av=!"=="!~1!" set AntiVirus="%AntiVirus%%av%"
     )
    GOTO:EOF
    
    echo.
    echo.
    echo %AntiVirus% found
    echo.
    echo Script created by Matthew Ammann, revised by Andriy M from StackOverflow
    
    @pause

Here's the output redirected to a logfile:


    C:\AVFinder>set AntiVirus="Initial Value" 
    
    C:\AVFinder>set AVList=(adobe ccleaner auslogics) 
    
    C:\AVFinder>SETLOCAL EnableDelayedExpansion 
    
    C:\AVFinder>echo Checking Program Files... 
    Checking Program Files...
    
    C:\AVFinder>if "AMD64" == "AMD64" (
    echo 64-bit OS  
     echo. 
     for / %f in ("C:\Program Files (x86)\*") do (
    echo "%f"  
     SET "folder=%f"  
     REM Begin loop to search substrings with words in AVList  
     Call:SearchAV "C:\Program Files (x86)\Adobe" 
    ) 
    ) 
    64-bit OS
    
    
    C:\AVFinder>(
    echo "C:\Program Files (x86)\Adobe"  
     SET "folder=C:\Program Files (x86)\Adobe"  
     REM Begin loop to search substrings with words in AVList  
     Call:SearchAV "C:\Program Files (x86)\Adobe" 
    ) 
    "C:\Program Files (x86)\Adobe"
    "" was unexpected at this time.
    
    C:\AVFinder>  if /I NOT "!~1:av=!"=="!~1!" set AntiVirus=""Initial Value""(adobe ccleaner auslogics)""


Where am I going wrong?