The Command Prompt is one of the best features in Windows 10 that allows users to run various commands and fix many challenging issues. It is commonly known as ‘CMD’ in the Microsoft users community. You can learn to execute many basic commands using this feature. One of these operations is how to change directory in CMD.
Before the graphical user interface was introduced, all operations on the Windows DOS were executed in the form of commands. These were commands related to changing a folder name, searching files and folders, deleting files, switching directories, and much more. As a result, multiple Command Prompt tricks can help you complete tasks effectively with a better speed.
How To Change Directory In CMD In 4 Ways
The command for changing the directory is known as the CD command. When you open the Windows Command Prompt in any version, the default path is set to C:WindowsSystem32 in the administrator mode or C:Users<user name> in the normal mode.
You can change directory in CMD in four ways. Let’s check out the details for how to change directory in CMD.
1. How To Change Directory In CMD Using CD Command
Changing the current working directory in the Command Prompt is a simple task. You need to open the Command Prompt in normal mode for this purpose.
To start with, press the Windows key + R to open the Run command. Then, enter CMD in the search field and press the Ctrl + Shift + Enter combination to open the elevated Command Prompt window.
You can use the command CD to change the directories in the Command Prompt and navigate to different directories and folders.
To go to a specific directory, type cd + (directory location). For instance, cd C:Program Files.
To open a specific folder, type cd + (folder name). For example, cd Common Files.
You can see that the directory is now changed to the Common Files after using the CD Windows command line.
To enter the subdirectory in a single command, you can do it in the way given below.
cd C:Program FilesCommon Files
Users can type cd.. to go up a level in the Windows directory tree they are currently working on. In our case, the Program File folder becomes the main directory once we use this command.
Next, you can use the dir command to check the subdirectories of the current directory using the dir command, as shown in the image below.
Using the dir command, you can see all the folders(directories) in the Program Files folder.
Suppose you wish to go to the root level directory from any other directory in the file system, type cd, and press the Enter key. Here, we were taken to the C drive – the root directory – after using the command.
2. Change The Paths In The Command Prompt
If you are wondering how to change directory in CMD, you can start by changing the paths of the Command Prompt.
Note: There are two options to execute this method. We have explained both in detail below. You can opt to change any of the paths as per your choice. If one doesn’t work, you can then try out the next.
Option 1: Change The Start In Path
First, enter CMD in the Start menu search bar and right-click on select ‘Open file location’ in the right pane.
Now, right-click on the Command Prompt and select Properties from the context menu.
Go to the Shortcut tab and change the Start-in path to a location of your choice. Then, click on Apply and OK to save the changes.
Once you are done with the changes, verify if the path has been changed correctly. This method will work only if you open the Command Prompt in the normal mode.
Option 2: Change The Target Folder
If the Start in method doesn’t work effectively, you can change the target folder of the Command Prompt and verify if it does the trick.
You need to follow the same steps as we saw in the previous method. The only difference is to change the Target path to the following:
%windir%\system32\CMD.exe /k "cd C:\"
The ‘C’ letter indicates the drive, which is our desired directory path. If you select a folder as your desired path, make sure you mention it along with the drive. Doing this will change the current working directory in Command Prompt when you run it with administrative privileges.
3. Use The Registry Editor
Registry editor is another way to know how to change directory in CMD if the previous solutions haven’t worked well for you. We recommend using this only after trying out the previous solutions.
To start with, press the Win key + R keyboard shortcut to open the Run command. Next, enter ‘regedit’ in the search field and press the Enter key.
Next, go to the path given below.
Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor
Once you open the Command Processor folder, right-click in the right pane, select New, and choose String Value. Name the String Value ‘Autorun.’
Double click on the newly created Autorun and update the value data to cd /d C:Program Files. C is the drive letter(directory), and Program Files is the folder in it. Then press Enter key or click on the OK button to save the changes.
4. How To Change The Directory Using A Batch File
Another method, albeit a comparatively complex one, is to create a batch file and change the default directory in Command Prompt. You need to create a batch file in this method.
To create a batch file, you need to open a new Notepad file. Then, type the script given below. We have used the following path (C:Program FilesCommon Files) for this example. You can choose the relative path as per your preference.
set path=C:Program FilesCommon Files
cd %path%
Here, the path is the variable used in the script. You can use any variable name as per your wish, but make sure you make appropriate changes in the script accordingly.
Then, save the file with a .bat extension. Also, make sure you select All Files in the Save as type section and then save the file.
Now, open the Command Prompt. Type cd desktop and press the Enter key to set the desktop as your default directory.
We have saved the batch file on the Desktop. If you saved it in some other directory, you need to navigate to that directory/folder.
Then, enter the bat file name and press Enter key to run it.
You will see that the default directory of the Command Prompt is changed after executing the batch file. That’s all you need to know about how to change directory in Command Prompt.
Conclusion
The Command Prompt is one of the essential features in Windows 10 that allows users to resolve issues using specific commands. There are multiple methods to understand how to change directory in CMD in Windows 10; you can opt for any way that is easy for you to comprehend.
To change the default home directory in the Command Prompt, you need to use it in the normal mode. Make sure you use the registry editor method only after trying out the simple ways to change the directory. It’s also a good idea to backup your registry settings before you make any changes so that it’s easy to revert back to the original settings if anything goes wrong.