Page 1 of 1

Search for file name with or without parentheses

Posted: 2022-Dec-30, 4:09 am
by vb88
Hi, I used below batch script try to locate the drive which contains the subdirectory to get
the file(s) with similar names. Please note not all of the file name has two names (see my screenshot). How to correct my script to achieve this goal.

Code: Select all

set pc=DS-15-103-W
goto pcname


:pcname
REM Locate the Drive contains the folder-"Site Information"
set mydrive=NOT_FOUND
for /f "skip=1" %%G in ('wmic logicaldisk get name') do (
    if exist "%%G\Site Information" set mydrive=%%G
    )
echo Possible USB Drive is %mydrive%  
if %mydrive%==NOT_FOUND (goto nas) else (goto check)


:check
REM Locate the executable file with full path
set pathdrive=NOT_FOUND
[color=#FFFF00]for /f "tokens=* delims=\" %%a in ('dir "%mydrive%" /s /b ^| find /i "(%pc%).exe"') do set "pathdrive=%%~dpnxa"[/color]
echo. The file path is %pathdrive%
if "%pathdrive%"=="NOT_FOUND" (goto nas) else (goto extract)
And I tried to use below script but it did not work out either.

Code: Select all

for /f "tokens=* delims=\" %%a in ('dir "%mydrive%" /s /b ^| find /i "(%pc%)(2).exe"') do set "pathdrive=%%~dpnxa"