Search for file name with or without parentheses

Microsoft Windows
Post Reply
vb88
Posts: 2
Joined: 2022-May-22, 1:11 am

Search for file name with or without parentheses

Post 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"
Attachments
batch_screenshot2.PNG
batch_screenshot2.PNG (68.36 KiB) Viewed 9796 times
batch_screenshot.PNG
batch_screenshot.PNG (88.25 KiB) Viewed 9796 times
CENAS_DSAO.PNG
CENAS_DSAO.PNG (35.01 KiB) Viewed 9796 times
Post Reply