SIMMS7400 wrote:Is there a way to add additional code to only read back in a certain line? For instance, this output gives me two locations. While either util will be ok, I like to use the Utility.bat on line 2. Since this will read back in the first line, anyway to grab the second?
You're taking kind of a roundabout approach to this. There's no need to create, read, and delete a file when you can use the value directly. Instead of finding one line in a file, just get one line in the first place, and store it directly into a variable. A few people have already pointed out that a FOR loop will do this for you.
The command
where /r "C:\Oracle\Middleware\user_projects" "Utility.bat" will return only the second line, because we've used the /R switch to tell WHERE to start looking in the right place.
Code: Select all
@ECHO OFF
FOR /F "TOKENS=* DELIMS=" %%F IN ('WHERE /R "C:\Oracle\Middleware\user_projects" Utility.bat') DO SET "UTIL_PATH=%%F"
ECHO %UTIL_PATH%
PAUSE
Of course, this means you'll need to pass both the starting directory and the file name as arguments to the script. My earlier answer addresses that. It also addresses running the command immediately, instead of storing it into a variable first.
It's worth noting that FOR will iterate over each result returned. In an instance where the DO portion is a SET command, this means the variable will be set as many times as there are results, with the last one being the one that sticks. If we ran
for /f "tokens=* delims=" %%F in ('where /r %cd:~0,3% Utility.bat') do set "util_path=%%F", the variable
util_path would first be set to
C:\Oracle\Middleware\EPMSystem11R1\common\utilities\LCM\11.1.2.0\bin\Utility.bat, and then to
C:\Oracle\Middleware\user_projects\epmsystem1\bin\Utility.bat. In this specific case, that suits your needs, but it's often hard to be certain the results will be returned in the order you want, so it's best to not count on that. Instead, set up the command (piping through one or more FIND commands, if necessary) so that only the result you want makes it through.