Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-11-16
4
Medium Priority
?
76 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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