user3265987
user3265987

Reputation:

Call another .bat file from within the same folder?

I have my primary Batch file in a folder with a second batch file in the same folder. How do I make it so that the second batch file can be called from within the first. This must be able to work with any user's Windows computer.

I figured it was something like this (in the primary file):

call C:\%UserProfile%\#Hashtag\gameData\second.bat

But it says my syntax or path is incorrect.

Upvotes: 5

Views: 3881

Answers (3)

Stephan
Stephan

Reputation: 56198

call "%~dp0second.bat"

%~dp0 gives you the path (including a trailing backslash) of the location of your currently running batchfile.

Upvotes: 13

Torqane
Torqane

Reputation: 156

Agreeing violently with @Stephan, there's a sort of invisible change to the code besides using the %~dp0, in that the path now is also in " double quotes. That's most likely the issue with the first one because of expansion of the %UserProfile% variable... my guess is there's a space in that string.

There's no issue using the # character in a filename.

Upvotes: 1

Abhi
Abhi

Reputation: 744

Maybe due to the folder name #hashtag it is throwing an error. Add the folder path to PATH variable and then try calling the batch file name directly.

Upvotes: 0

Related Questions