I have a batchfile script that I wrote as an interface for connecting to my network shares. At this point it’s very simple. It has a list of my shares that I would like to compare to network shares in use and disable that share as option if it’s found. The following code snippet is part of a for loop that iterates over the number of shares in the list and lists them.
setlocal enabledelayedexpansion
set list[0]="\\xxx.xxx.x.xx\photo"
set list[1]="\\xxx.xxx.x.xx\photo 2"
for /l %%n in (0,1,2) do (
rem wmic netuse get remotename |findstr /C:!list[%%n]!
rem if %errorlevel% neq 0 do(command 1) else (command 2)
echo %%n !list[%%n]!
)
The rem
above is removed for testing the problem.
The thought here is to use if %errorlevel%
condition to catch the match. The shares are echoed with double quotes. If for example photo is mounted, both photo and photo 2 will be matched which is undesirable.
Since the shares have similar names and added number with space I need to compare the strings exactly so I have tried with findstr /x
switch but this doesn’t work at all. Not sure if the entry with double quotes interferes. Removing the double quotes in the list yields an error that number after the space cannot be opened. Am I approaching this in a correct way?