0

I want D:\Desktop\Test0\Test1\batch1.bat to execute D:\Desktop\Test0\Test2\app.exe without determing a specific path because the D:\Desktop\Test0 folder gets moved around a lot.

What is the variable for this? Unfortunately I can't find it because I don't know what the proper name for this intention is.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Clacers
  • 401
  • 2
  • 6
  • 12

2 Answers2

0

Microsoft.com - Using batch parameters

If you use these batch file processors you should be able to pull out the parts of the path that you care about and create a new path to app.exe. Don't forget to put quotes around the variables otherwise you will not handle spaces and other special chars in filenames.

Here's an example of similar question: Batch Extract path and filename from a variable

Martin
  • 2,316
  • 1
  • 28
  • 33
0

A batch file can refer to itself when using %0. According to this page, you can change the returned string by adding ~-modifiers, like ~f to get the full path, ~nx to get the pure file name or ~dp to get the path to the parent directory, just to list a few.

In you situation, you simply need to use %~dp0 in the batch file batch1.bat to get its container directory, then get one level up .. to exclude the immediate parent directory Test1, and then append the remaining relative path to the program app.exe, like this:

"%~dp0..\Test2\app.exe"
aschipfl
  • 33,626
  • 12
  • 54
  • 99