I'm trying to run a batch file that exists in one folder, from a batch file in another folder:
Parent folder Big containes 2 folders BatchFolder and Medium. BatchFolder contains a batch file called Batch1. Medium contains another folder called Small. Small contains a batch file called Batch2 that needs to run Batch1. The command prompt is run from the location of Batch2
Therefor, how do I navigate up the folders To Big, and then navigate into the BatchFolder?
I've been trying alsorts to achieve this with no success, such as Bacth2 containing the following "call ../BatchFolder/Batch1.bat"
I'm not sure whether you really need to navigate to the required folder (i.e. set it as the current one) or you simply need a way to call the batch script in that folder using a relative path notation. Navigating, from how I understand the term, means the former, but your last sentence seem to show that you need the latter.
First, the answer:
Next, what it means.
%~dp0%
is a variation of%0
: the latter is the full path to this batch file (i.e.Batch2.bat
) including the file name, and the former is the full path to this batch's folder (including the trailing\
)...
points to the immediate parent folder. It is repeated twice because we need to access the 'grand-parent' of theBatch2.bat
's folder, and the grand-parent isBig
. Once we are pointing toBig
, we can address the files/folders in it, in this case it'sBatchFolder
that we need, and eventually we can put the name ofBatch1.bat
.This works regardless of what the current folder is. That is, in case I wasn't clear on that head, by simply calling a batch file you are not yet changing the current folder. You would have to use the
CD
command for that. That would be navigating (but I'm still open to being corrected as to my understanding of this term).