Batch File - going back two steps in a directory path

后端 未结 3 1174
走了就别回头了
走了就别回头了 2020-12-18 14:00

I am creating a batch file i am on a path

C:\\Validation\\docs\\chm

I want to move back to the

C:\\Validation part 
         


        
3条回答
  •  情歌与酒
    2020-12-18 14:35

    Until you give more details as to the script in question, we can only guess to what the problem may be.

    However, since you are changing the current directory only for a limited time you should be using the pushd and popd commands.

    Example: (Run this .bat script to see how pushd and popd work!)

    :: 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
    

    For help type pushd /? or popd /? into the command prompt.

提交回复
热议问题