Link to home
Start Free TrialLog in
Avatar of Adam Handley
Adam Handley

asked on

Batch file to check if a folder exists with a certain word in

Hi,

Hopefully you can assist.

I would like to create a batch file to check if a folder exists. Each folder name is unique but has the same word 'Bomgar' within it. If the file exists then we will not run an executable. If it doesn't then it will run the executable.

I have tried the IF NOT EXIST command but not sure how to check for a word within a folder.

Thanks in advance.

Adam
Avatar of oBdA
oBdA

Sorry, I can't quite follow what it is you want to achieve.
For a given parent directory, you can do the following to check if it has a subdirectory with 'Bomgar' in it:
set Parent=C:\Temp
dir /a:d /b "%Parent%" | find /i "Bomgar" >nul
if not errorlevel 1 (
	echo 'Bomgar' folder found in %Parent%, leaving ...
	goto :eof
)
echo 'Bomgar' folder not found in %Parent%, doing something ...
REM ...

Open in new window

If you need something else, you need to elaborate a bit.
Avatar of Adam Handley

ASKER

Thank you for your response and apologies for not being clear.

What i need to do is check in C:\ProgramData to see if a folder within there exists. The folder name will always have 'Bomgar' within it but then a unique identifier i.e 'Bomgar12345'. If this folder exists then we know the service has been installed and therefore doesn't need to be installed again. If that folder doesn't exist then we will want to run an executable to install.

Thanks again for your help.

Adam
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, thanks for the prompt response and solution.