Solved

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

Posted on 2016-11-16
4
47 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
  • 2
  • 2
4 Comments
 
LVL 84

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 84

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

827 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