Solved

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

Posted on 2016-11-16
4
70 Views
Last Modified: 2017-01-25
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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 41889892
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
ID: 41889903
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 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 41889911
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
ID: 41889932
Perfect, thanks for the prompt response and solution.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 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