Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a command to change the current directory to default directory? (I'm not asking about permanently changing the default directory, here!)

For example, if the current directory is "..\xyz" and my default command prompt directory is D:\Abc, is there a way to navigate directly to D:\Abc (without giving >cd D:\Abc)?

share|improve this question
There is a great answer here.. – Anindya Chatterjee Apr 5 '14 at 21:19
up vote 3 down vote accepted

There's no option built into cd to do this but you could certainly create a .cmd script file that does it. For example, you could put this into a home.cmd file somewhere on your search PATH and go to D:\Abc just by typing home:

@ echo off
cd /D D:\Abc
share|improve this answer
Or call home in batch files ;) – Joey Dec 14 '12 at 6:19
Might I point out the security risk? - I can just add malicious code to your batch file or even have a similar named file earlier in the PATH and you wouldn't have an idea. Having batch files available in path is so wrong for security. – Dheeraj Bhaskar Nov 19 '14 at 11:26
There's nothing special about scripts. You could have the same problem with malicious code in an .exe earlier in your PATH and you also wouldn't have an idea. – Nicole Hamilton Nov 25 '14 at 16:15

There's no in-built command, but why not create your own, for example dd (Default Directory)? Just save the following command in a batch/script file in any location, say C:\Macros.bat or C:\Macros.cmd:

@doskey dd=cd /d D:\Abc

Now in the registry (Regedit.exe) navigate to:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor

Create a string value (REG_SZ) or expandable string value (REG_EXPAND_SZ) called AutoRun and set it to C:\Macros.bat (or .cmd as the case may be).

The same AutoRun value can also be added to:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

Any commands specified in the HKLM AutoRun value will run before those in the HKCU counterpart. See cmd /? for more.

Now whenever you open a cmd.exe instance/window, Macros.bat (or .cmd) will be executed automatically and the DOSKey command alias will be (re)created as a result. So you can simply type your new command dd to jump to the specified default directory.

share|improve this answer

Although creating a batch file as Nicole mentions is probably easier.

share|improve this answer
though on my computer cmd.exe defaults to c:\windows\system32 for some reason, regardless of the fact that %HOMEPATH% is the user profile. – barlop Dec 14 '12 at 7:01
@barlop Are you running cmd from a shortcut, the file directly, or from the run dialog? – David Ruhmann Dec 14 '12 at 16:59
@DavidRuhmann<ENTER> on xp. But looks like I might've found what makes the difference. In the registry HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor Having a Key called Autorun, with no value. Try that. And see if yours goes to c:\windows\system32 It might be that you don't have the key at all. For example, if I rename the key to autorunn(like no autorun key at all no doubt) then the cmd prompt goes to %homepath%. If the key is called Autorun with no value, then it goes to c:\windows\system32 – barlop Dec 14 '12 at 17:26
On a related note. In Windows 7 if you run cmd with administrative privileges it goes to c:\windows\system32 as well though I haven't checked if that's related to administrator on my comp anyway not having a profile as i haven't tried logging in as that. but i doubt it's because of that, as i've heard that in win7, unlike xp. runas administrator sticks to the same profile, which (in my case anyway) has administrative privileges, and just elevates the process to use that. – barlop Dec 15 '12 at 14:54

Well, if your command line started out in D:\Abc and you only need to be in ..\xyz for a few commands, use the pushd and popd commands. Here is a batch script example:

@echo off
echo.Im at this directory: %CD%
pushd "..\xyz"
echo.Im now at this directory: %CD%
echo.Im back at this directory: %CD%

Otherwise you will need to use the cd command to change the current directory. This only works for a batch script.

@echo off
echo.Im at this directory: %CD%
cd "..\xyz"
echo.Im now at this directory: %CD%
cd "%~dp0"
echo.Im back at this directory: %CD%

Note that "%~dp0" will take you back to the original directory in which the batch script started.

share|improve this answer
Note that a in batch file located in directory A, but executed from directory B, %~dp0 will point to directory A, not necessarily the starting directory. – Marcks Thomas Dec 14 '12 at 16:24
@MarcksThomas That is correct, I tried to make that point with my last note in the answer, I guess it was not clear enough. – David Ruhmann Dec 14 '12 at 16:50

This is a universal command to create the "home" command tool on any Windows machine.

Press WinR and enter the following command:

share|improve this answer

I know I'm late to the game but I would like to post my solution for anybody that stumbles across this question (Like me). I created a simple how-to that nobody else has mentioned and it's easier and more direct IMO. Check it out: Spiceworks - Change Default Directory

  1. Open the Command Prompt's Location.

    On the start screen / menu, type in "cmd", right-click it and select "Open File Location".

  2. Open the Command Prompt Properties and change the "Start In" Property.

    Right-click on the "Command Prompt" icon, select "Properties", and edit the "Start In" property to your desired path.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .