I am trying to detect the drive letter that contains removable media (i.e. a memory stick) via wmic logicaldisk get caption^,description^,drivetype 2^>NUL then I want to use dir to get the name of the file on the drive (there should only be one but I don't know what the name is) and pass that filename into netsh wlan add profile.
I have this batch file I have written:
@echo off
for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 2^>NUL`) do (
if %%l equ 2 (
SET file= | dir %%i /b
echo %%i\%file%
netsh wlan add profile filename="%%i\%file%" user=all
)
)
pause
and I expect the output to be D:\%some file%.xml but I am only getting D:. It seems that the variable %file% is not being set correctly.
I've tried many variations but I can't get it to set properly. Any suggestions welcome!
fileto set to? actually you are redirecting (piping) the output ofset file=intodir %%i /b... anyway, you need delayed expansion forfileas you are changing and reading the variable in the same block of code... also you defined only three properties in thewmiccommand line but fourfor /Ftokens... finally you are readingVarbut you never set it...