【问题标题】:Batch File - going back two steps in a directory path批处理文件 - 在目录路径中返回两步
【发布时间】:2012-12-13 18:18:13
【问题描述】:

我正在创建一个批处理文件,我在一个路径上

C:\Validation\docs\chm

我想搬回去

C:\Validation part 

在 %DialogPath% 这是用户输入的,但是当我写的时候

CD /D %DialogPath%

发生错误提示此路径不存在

【问题讨论】:

  • 您还没有提出问题。请编辑并包含一个正确的问题。还显示任何相关代码,尤其是定义 DialogPath 的代码。
  • 这可能与您当前的问题无关,但您应该引用您的路径以便能够处理其中包含空格的路径。即cd /D "%DialogPath%"。或者更好的是,先去掉引号,以防用户使用~ 输入它们,然后添加您自己的:cd /D "%~DialogPath%"

标签: batch-file cmd window


【解决方案1】:

您的问题的直接答案是

cd ..\..

但是cd /D C:\Validation 也可以。

这个问题更可能是变量而不是命令。

【讨论】:

    【解决方案2】:

    在您提供有关脚本的更多详细信息之前,我们只能猜测问题可能是什么。

    但是,由于您只在有限时间内更改当前目录,您应该使用pushdpopd 命令。

    示例:(运行此 .bat 脚本以查看 pushdpopd 的工作原理!)

    :: Hide Commands
    @echo off
    
    :: Display Current Working Directory
    echo Current Directory = %CD%
    
    :: Create folders for demonstration purposes only
    rd /Q "%Temp%\Test" 2>nul & mkdir "%Temp%\Test" & mkdir "%Temp%\Test\Subfolder"
    
    :: Change the Working Directory
    pushd "%Temp%"
    
    :: Display Current Working Directory
    echo Current Directory = %CD%
    
    pushd "%Temp%\Test\Subfolder"
    
    :: Display Current Working Directory
    echo Current Directory = %CD%
    
    :: Revert back to the previous Working Directory
    popd
    
    :: Display Current Working Directory
    echo Current Directory = %CD%
    
    :: Revert back to the previous Working Directory
    popd
    
    :: Display Current Working Directory
    echo Current Directory = %CD%
    
    pause
    

    如需帮助,请在命令提示符中键入 pushd /?popd /?

    【讨论】:

      【解决方案3】:

      您可以使用cd .. 向上移动一条路径。如果您这样做两次,您将进入C:\Validation 目录。

      在您的示例中,它看起来像这样:

      C:\Validation\docs\chm> cd ..
      
      C:\Validation\docs> cd ..
      
      C:\Validation>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-12
        • 2013-11-20
        • 2016-01-12
        • 2014-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多