在命令提示符目录导航 [英] Directory navigation in command prompts

查看:135
本文介绍了在命令提示符目录导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行存在一个文件夹中的批处理文件,从另一个文件夹中的批处理文件:

I'm trying to run a batch file that exists in one folder, from a batch file in another folder:

父文件夹大containes 2个文件夹BatchFolder和网上平台。
BatchFolder包含一个名为BATCH1的批处理文件。
中含有一种称为小另一个文件夹。
小包含一个名为Batch2一个批处理文件,需要运行BATCH1。
命令提示符从Batch2的位置运行。

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

为此,我该如何向上导航文件夹到大,然后导航到BatchFolder?

Therefor, how do I navigate up the folders To Big, and then navigate into the BatchFolder?

我一直在试图alsorts没有成功,如Bacth2包含下面的呼叫../ BatchFolder / Batch1.bat来实现这一目标。

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.

首先,答案:

call %~dp0%..\..\BatchFolder\Batch1.bat

接下来,就是这个意思。 %〜DP0%是一个变化%0 :后者是这个批处理文件的完整路径(即 Batch2.bat ),包括文件名,前者是这个批次的文件夹的完整路径(包括尾随 \\ )。

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 \).

.. 指向直接父文件夹。它被重复了两次,因为我们需要访问 Batch2.bat 的文件夹中的祖父母,和祖父母为。一旦我们都指向,我们能够解决文件/文件夹在里面,在这种情况下,它是 BatchFolder 我们需要,最终我们可以把名称 Batch1.bat

.. points to the immediate parent folder. It is repeated twice because we need to access the 'grand-parent' of the Batch2.bat's folder, and the grand-parent is Big. Once we are pointing to Big, we can address the files/folders in it, in this case it's BatchFolder that we need, and eventually we can put the name of Batch1.bat.

该作品无论的当前文件夹的是什么。也就是说,如果我不上头脑清醒,通过简单地调用批处理文件,你还没有改变当前文件夹。你将不得不使用 CD 命令的。这将是的导航的(但我仍然开放给被纠正,以我的这个词的理解)。

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).

这篇关于在命令提示符目录导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆