Solved

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

Posted on 2016-11-16
4
15 Views
Last Modified: 2016-11-16
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
0
Comment
Question by:Adam Handley
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
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.
1
 

Author Comment

by:Adam Handley
Comment Utility
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
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
Here's the fleshed out version:
@echo off
setlocal
set Parent=C:\ProgramData
set Keyword=Bomgar
dir /a:d /b "%Parent%" | find.exe /i "%Keyword%" >nul
if not errorlevel 1 (
	echo '%Keyword%' folder found in %Parent%, leaving ...
	goto :eof
)
echo '%Keyword%' folder not found in %Parent%, installing service ...
REM Add your setup here ...

Open in new window

0
 

Author Closing Comment

by:Adam Handley
Comment Utility
Perfect, thanks for the prompt response and solution.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now