Search for exe but exclude a certain directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Search for exe but exclude a certain directory

#1 Post by SIMMS7400 » 10 Sep 2017 06:02

Hi Folks -

I have a "utility" script I run every time I begin to stand up automation on a server. What it does is develops the necessary directories and "stater" batch scripts for the environment.

The "starter" set batch scripts are built based on if a specific Oracle/SQL utility is found. However, when installing the Oracle suite, there are sometimes (2) instances of the same "exe" in (2) different directories. I was hoping to modify my current search pieces of syntax to in a way that would ignore the path if finds if "EPMSYSTEMR1" is in the path, and proceed to the next found occurrence?


Code: Select all

for %%D in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist %%D: (
   for /f "delims=" %%A in ('dir/b/s %%D:\epma-batch-client.bat 2^>nul') do (
      SET EPMA_BATCHPATH=%%A
   )
)

Thank you!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Search for exe but exclude a certain directory

#2 Post by aGerman » 10 Sep 2017 07:41

You could filter the output of the DIR command using FINDSTR /V.

Code: Select all

   for /f "delims=" %%A in ('dir/b/s %%D:\epma-batch-client.bat 2^>nul^|findstr /vc:"\\EPMSYSTEMR1\\"') do (

Steffen

Post Reply