Search code examples
batch-fileeditnotepad

Open .bat as txt from another .bat file


How do I open a .bat file as a text file in notepad from another batch script.

What I actually want is to open a file b.bat in notepad using a batch script say a.bat

i tried:

start notepad tools_OriginalBuild\repository_test.bat

doesn't work


Solution

  • At the moment, your path is relative, so you could only run that batch file from the directory containing the batch file (provided the relative path given is correct). Running it from any other directory would result in an error about the file not being found.

    You can eradicate this problem, by always running relative to the batch file's location using the following code inside your batch file:

    notepad %~dp0\tools_OriginalBuild\repository_test.bat
    

    Information on this format can be found here: What does %~dp0 mean, and how does it work?

    This makes the assumption that that sub directory exists and the file exists, of course. You could check for its existence first, if you wish, but that's another question for you to investigate on your own :)