I'd like to use a batch file to call a different batch file that is in a sub directory. For instance, if my file system look as follows:
MainFolder
main.bat
FirstDirectory
SecondDirectory
foo.bat
Then main.bat might look something like this:
echo on
REM This lines tells the user what this bat file is doing
call ant
call \SecondDirectory\foo.bat
I'm looking for a one line solution which I think does not exist. Unfortunately I don't always want to do this with a batch file and want to do it directly from the command line.
Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME. bat.
If you want to move to a subdirectory of another parent directory or if you want to move up to the root of the drive, you would want to use CD \ (please note that there is a space between CD and the backslash character). If you type CD \ and press Enter, you will then be at the root of the current drive.
Run a batch file from the Command Prompt To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.
Using a BAT file in Windows is as simple as double-clicking or double-tapping it. You don't need to download any special program or tool. To use the first example from above, entering that text into a text file with a text editor and then saving the file with the .
You can indeed call a batch file from another batch file using the call
command. As @Blorgbeard states, the issues is the leading backslash \
. Removing it indicates SecondDirectory
is relative to the current working directory.
call SecondDirectory\foo.bat
A word of caution: the call
command essentially inserts called code in at run time. Be careful to avoid variable name collisions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With