1.

Solve : Finding an .exe within multiple directories?

Answer»

Hello all!

I'm wanting to create a batch file that will search for a specific .EXE and run it once it finds it.

For instance:

e:
cd\winnt
setupnw.exe/acu/u:e:\winnt\unattend.txt

Where the "/acu/u:e:\winnt\unattend.txt" is a way to run the setup with the settings in the unattend.txt file. So, in theory, if setupnw.exe was always within the directory e:\winnt, I wouldnt have this PROBLEM, and with limited knowledge of DOS, I wouldnt even know where to begin.

In all, I'm wanting DOS to search through C:, D:, E: etc until it finds the setupnw.exe, then run the setup.exe/acu/u:x:\winnt\unattend.txt where x: is the drive it found the setupnw.exe on.

Thanks in advance!



This wouldn't be the first time I made a stab at something I really don't understand. Searching disks with batch language is LABOR intensive. This little snippet may run a while.

Code: [Select]@echo off
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"') do (
for /f "tokens=* delims=" %%x in ('dir %%i:\ /s /b ^| find /i "setupnw.exe"') do (
if errorlevel 1 setup.exe/acu/u:%%~dx:\winnt\unattend.txt
)
)

Good luck. lol. Indeed!

Well, this could be an easier way to do it.

Is there a way of instead of searching the directories, to default the "x:" drive to where ever the batch file was ran from?

For instance, if the batch file was ran from "e:\winnt" that it'd run:

e:
cd\winnt\
setupnw.exe/acu/u:e:\winnt\unattend.txt

Or if the batch file was ran from the "f:\winnt" that it'd run:

f:
cd\winnt\
setupnw.exe/acu/u:f:\winnt\unattend.txt

Only reason I hesitate to use yours is that we do have some network DRIVES, and depending on the department they're in, it could take a long long time

Thanks!I still don't fully understand the question, but now that I'm knee deep in it, I'll just continue on. You can derive the drive from this: SET drive=%cd:~0,2%

Seems logical you could simply replace the drive letter with the variable:

setupnw.exe/acu/u:%drive%\winnt\unattend.txt

Let us know how it goes.

Note: this could work from the command line unless the setupnw.exe was found in a directory on the path and not in the current directory. If run from a shortcut, results could be unpredictable.Right on the money.

A big internet man-hug goes out to you good sir!



Discussion

No Comment Found