1

I have a txt file to a specific path that contains one or more line just like the following:

Directory of c:\folderA\folderB
Directory of c:\folderC\folderD

these are the paths of a program example.exe. I want automatically to find the path that example.exe exists in my computer and to run it from a .cmd script. So far i have succeed to log the paths of existence to a txt. How can I set a variable with only the path of the first line?

The final result should be var_path=c:\folderA\folderB

Marco
  • 56,740
  • 14
  • 129
  • 152
George
  • 43
  • 1
  • 4

1 Answers1

0

A quick and dirty solution is:

@echo off
Call :getFirstDirectory
::do your stuff with %var_path%. For example:
@echo %var_path%

exit /b

:getFirstDirectory
for /f "tokens=3" %%a in (dirs.txt) do (
set var_path=%%a
exit /b
)

Which assumes that dirs.txt is the file containing:

Directory of c:\folderA\folderB
Directory of c:\folderC\folderD
steenhulthin
  • 4,553
  • 5
  • 33
  • 52