3

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 

which is in %DialogPath% This was entered by the user but when i write

CD /D %DialogPath%

An error occurs that tells this path does not exists

aschipfl
  • 33,626
  • 12
  • 54
  • 99
user1926152
  • 235
  • 2
  • 8
  • 13
  • 3
    You have not asked a question. Please edit and include a proper question. Also show any relevant code, especially code that defines DialogPath. – dbenham Dec 28 '12 at 13:47
  • This is probably not related to your current problem, but you should quote your path to be able to handle paths with spaces in them. I.e., `cd /D "%DialogPath%"`. Or better yet, strip quotes first in case the user entered them with `~` and then add your own: `cd /D "%~DialogPath%"` – indiv Dec 28 '12 at 15:30

3 Answers3

9

The direct answer to your question would be

cd ..\..

But cd /D C:\Validation also works.

The problem is more likely with the variable than then command.

Patrick Meinecke
  • 3,963
  • 2
  • 18
  • 26
4

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.

David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
2

You can move up one path with cd ... If you do that twice, you will land in the C:\Validation directory.

In your example it would look like this:

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

C:\Validation\docs> cd ..

C:\Validation>
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
eclipse32
  • 21
  • 1