- Tips for changing directories in windows command line
- Change directory
- Change to a directory with spaces in the name
- Change drive and directory with single command
- Tips for changing directories in windows command prompt
- Use Pushd and Popd commands:
- Using cd command in Windows command line, can’t navigate to D:\
- 9 Answers 9
- It did work, as the command is designed to work.
- Command Prompt: 11 basic commands you should know (cd, dir, mkdir, etc.)
- 1. How to change the directory (folder) in Command Prompt (CMD)
- 2. How to change the drive in Command Prompt (CMD)
- 3. How to view the contents of a directory in Command Prompt (CMD)
- 4. How to create a new directory with Command Prompt (CMD)
- 5. How to rename files and folders with Command Prompt (CMD)
- Command prompt won’t change directory to another drive
- 11 Answers 11
- The short answer
- More details
Tips for changing directories in windows command line
In Windows command prompt, we can change the directory using the command cd . Both cd and chdir refer to the same command. Syntax of this command is explained below with some examples.
Change directory
When we launch command prompt, the default directory it opens with is C:\Documents and Settings\logind. This is in Windows XP. In Windows 7 command prompt opens up with the directory C:\Users\loginid. Now let’s say you want to traverse to the directory C:\Windows\System32. The command for this is given below.
Change to a directory with spaces in the name
In Windows, we can have spaces in the directory names. cd command can interpret the space correctly. So we do not need to enclose quotes around the directory name, as with most of other windows commands. An example is shown below.
Change drive and directory with single command
The basic cd command does not work if you are trying to change to a directory that is located on a different drive. Say you are in C:\users\cmdadmin\ directory and want to change to E:\docs directory. If you run ‘cd e:\docs‘ you won’t get any error but you would still be in the same folder. Only when you switch the drive by running the command ‘E:’ you will move to the folder e:\docs. You can avoid this by using /d option with cd command.
This command changes to the drive E: and also changes the directory to E:\docs.
Tips for changing directories in windows command prompt
If you frequently work with windows command line, then the below tips would help you in easily changing the directories in command line.
Use Pushd and Popd commands:
Pushd command is similar to cd but it also saves the current directory path. So if you want go back to the directory where you have come from, you can just use popd command. It will take you to the last directory you were working in.
Pushd can remember all the previous directories you traversed as long as you change the directory using pushd instead of cd command. Using popd you can go back to all the previously visited folders in the reverse order. See the below example.
Using cd command in Windows command line, can’t navigate to D:\
This may be a silly question, and I think I have looked elsewhere to find the answer. Might be a path issue, but when I open the command line and type from the C:\> :
I cannot get to the D drive. Even if I type:
The command.exe will auto-complete the line with the tab key, so it knows where I’m at. It just doesn’t print to screen the result or actually get me there. This problem exists for the network drives as well.
Now, if I use the chdir ( cd ) command like this:
chdir D: or cd d:
I get the print out of the D:\ below the command but it still says I’m in the C:\ .
I feel like I’m missing something simple.
9 Answers 9
Going back to the days of DOS, there’s a separate «current directory» for each drive. cd D:\foldername changes D:’s current directory to the foldername specified, but does not change the fact that you’re still working on the C: drive.
What you want is simple:
Here you can see how the «separate current directory for each drive» thing works:
It did work, as the command is designed to work.
You simply don’t know how it’s actually supposed to work.
You’re not using a Unix or Linux shell program. The cd command in Microsoft’s command interpreter doesn’t behave as the cd commands in such shells do. It behaves somewhat differently. In particular, it doesn’t always change directory. In Unix and Linux shells, cd only ever sets the working directory. In Microsoft’s command interpreter, cd sometimes queries it. There’s no separate pwd command, so cd does two jobs.
If you give it no arguments, or an argument that is just a drive letter and a colon without a path, then it reports the current directory instead of changing it. If you give it no arguments, it reports the current directory of the current drive of the command interpreter process. If you give it only a drive letter and a colon as an argument, it reports the command interpreter process’ current directory of that drive. Each drive has its own current directory in the command interpreter. (This is a fiction maintained by the run-time libraries for Microsoft’s and several other vendors’ implementations of various programming languages. Win32 itself doesn’t work this way.)
So when you gave it d: as an argument, it reported the the command interpreter process’ current directory on drive D to you, which happened to be D:\ . If you’d given it no arguments at all, it would have reported C:\ to you.
If you want the cd command to always be in set mode and never be in query mode you need to add the /D option to it. This forces the command to always be in set mode, and also extends it so that it changes the current drive as well as changing a drive’s current directory. (In other words, it works more like the underlying Win32 API actually does.)
So, for example, the command line will change directory to whatever the current directory on drive D is, and also change the current drive to drive D.
If you want to change the command interpreter process’ current drive otherwise, the cd command is not the way. You do so by simply typing the drive letter and a colon:
Command Prompt: 11 basic commands you should know (cd, dir, mkdir, etc.)
Geeks and experts love the Command Prompt because of the advanced commands it can run. Fortunately, Command Prompt is not built only on advanced commands, but also on simple ones, designed to perform basic operations. In this article, we show you how to execute commands such as changing the current directory, switching to another drive, viewing the contents of a directory, creating and renaming folders, copying, deleting files and folders, and launching applications from the Command Prompt. We are also going to show you how to get help when using this app for Windows. Let’s get started:
NOTE: The information shared in this tutorial applies to Windows 10, Windows 8.1, and Windows 7. Note that, for simplicity, we are using screenshots taken only in Windows 10.
1. How to change the directory (folder) in Command Prompt (CMD)
The first command from the list is CD (Change Directory). This command enables you to change the current directory or, in other words, to navigate to another folder from your PC. For instance, the command CD takes you to the top of the directory tree. To see how it works, after you open the Command Prompt, type cd and press Enter on your keyboard. You should see how the CD command takes you to the top of the directory tree. In this case, to the “C:” drive.
Note that the Command Prompt is not case sensitive, meaning that you can type commands using capital letters, lowercase or any combination of them. The commands CD, cd or Cd, all work the same way.
Going back to the “CD” command, now you are working on the root of the “C:” drive. If you need to go to a specific folder from this drive run the command “CD Folder.” The subfolders must be separated by a backslash character: “.” For instance, when you need to access the System32 folder located in “C:\Windows,” type “cd windows\system32” as shown below, and then press Enter on your keyboard.
When you need to go one folder up, use the “cd..” command. Let’s assume that you want to go back to the Windows folder. Type “cd..” and press Enter on your keyboard.
The effect is that your current directory changes to “C:\Windows.”
2. How to change the drive in Command Prompt (CMD)
To access another drive, type the drive’s letter, followed by “:”. For instance, if you wanted to change the drive from “C:” to “D:”, you should type “d:” and then press Enter on your keyboard.
To change the drive and the directory at the same time, use the cd command, followed by the “/d” switch. The “/d” parameter is used to change the current drive to a specific folder from another disk volume.
For instance, if you are now on the “D:” drive and you want to go back to the Windows folder from the”C:” drive, you should type “cd /d C:\Windows” and press Enter on your keyboard, like in the following screenshot.
NOTE: By typing only the drive letter you automatically move to your most recent location on that drive. For instance, if you are on “D:” drive and type “cd c:\windows” nothing seems to happen. However, if you type “c:” then the working folder changes to “c:\windows,” assuming that it was the last folder you worked with on your “C:” drive.
3. How to view the contents of a directory in Command Prompt (CMD)
You can view the contents of a folder by using a command called DIR. To test it, we have created a folder named Digital_Citizen on the D: drive, with several files and subfolders. You can see them in the screenshot below.
The last time, our working folder was “C:\Windows.” To navigate to the folder mentioned above, we have to use the command “cd /d D:\Digital_Citizen.” To view the contents of the folder, type DIR, and press Enter. The list of the files and folders contained by it is displayed, together with some details about each of them (the size and the date and time when they were last modified).
4. How to create a new directory with Command Prompt (CMD)
You can make a new folder using the MKDIR (Make Directory) or the MD command. The syntax of these commands is “MKDIR Folder” or “MD Folder.”
Let’s say we need to create a new folder called Digital_Citizen_Life that is going to be placed in the “D:\Digital_Citizen” folder. To do that, we need to type “mkdir Digital_Citizen_Life” and then press Enter, as shown below.
To test if it worked, use the DIR command again. The newly created folder appears in the list.
NOTE: Do not forget that all these commands depend on the current location in the Command Prompt. For instance, if you are on the “C:” drive and type “MKDIR test,” the new folder is created in the root of the “C:” drive.
Another way to create a folder that does not involve being in the desired folder is to type the complete path of the new folder. For example, if you are working on the “D:” drive and you want to create a new folder in “C:,” called other_stuff, type “mkdir c:\other_stuff” and then press Enter.
When you need to create a folder with subfolders at the same time, you can use the “MKDIR FolderSubfolder” command. For instance, if we type “mkdir Digital_Citizen_Tests\Beta\Test1” three folders are created: Digital_Citizen_Tests, Beta and Test1, in a tree-like structure.
5. How to rename files and folders with Command Prompt (CMD)
To rename files and folders, you need to use the REN (Rename) command. To rename folders, type “ren Folder NewFolderName.” For example, if we wanted to rename the Digital_Citizen_Tests folder to Digital_Citizen_Final_Tests, we should run “ren Digital_Citizen_Tests Digital_Citizen_Final_Tests” and press Enter.
To rename a file, use the same command, like this: “ren filename.extension newname.extension”. For instance, to rename the Digital_Citizen_Picture1.bmp file to Image0.bmp, we have to run the command “ren Digital_Citizen_Image1.bmp Image0.bmp” command.
Read the second page of this tutorial if you want to learn how to copy files and folders, delete files and folders, start an application, and get help when using the Command Prompt.
Command prompt won’t change directory to another drive
I’m trying to compile some java (learning java currently), and to do so I need to change command-prompt’s directory (using javac).
It doesn’t change the directory. I try again using quotes:
Again it doesn’t change the directory. What am I doing wrong?
11 Answers 11
As @nasreddine answered or you can use /d
For more help on the cd command use:
Displays the name of or changes the current directory.
CHDIR [/D] [drive:][path] CHDIR [..] CD [/D] [drive:][path] CD [..]
.. Specifies that you want to change to the parent directory.
Type CD drive: to display the current directory in the specified drive. Type CD without parameters to display the current drive and directory.
Use the /D switch to change current drive in addition to changing current directory for a drive.
If Command Extensions are enabled CHDIR changes as follows:
The current directory string is converted to use the same case as the on disk names. So CD C:\TEMP would actually set the current directory to C:\Temp if that is the case on disk.
CHDIR command does not treat spaces as delimiters, so it is possible to CD into a subdirectory name that contains a space without surrounding the name with quotes. For example:
cd \winnt\profiles\username\programs\start menu
cd «\winnt\profiles\username\programs\start menu»
which is what you would have to type if extensions were disabled.
The directory you’re switching to is on another drive, you need to switch to that drive using :
then you can cd into the directory you want.
Use drive letter d for changing to D drive like:
When changing drives, you just need to type the drive letter, like d: (don’t use the backslash, like d:\; it doesn’t work).
You only use cd when moving between directories within the same drive.
The short answer
The correct way to go from C:\. \Admin to D:\Docs\Java drive, is the following command :
More details
If you’re somewhere random on your D:\ drive, and you want to go to the root of your drive, you can use this command :
If you’re somewhere random on your D:\ drive, and you want to go to a specific folder on your drive, you can use this command :
If you’re on a different drive, and you want to go to the root of your D:\ drive, you can use this command :
If you’re on a different drive, and you want to go to a specific folder on your D: drive, you can use this command :
If you’re on a different drive, and you want to go to the last open folder of you D: drive, you can use this command :
As a shorthand for cd /d d: , you can also use this command :
you should use a /d before path as below :
If you want to change from current working directory to another directory then in the command prompt you need to type the name of the drive you need to change to, followed by : symbol. example: assume that you want to change to D-drive and you are in C-drive currently, then type D: and hit Enter.
On the other hand if you wish to change directory within same working directory then use cd(change directory) command followed by directory name. example: assuming you wish to change to new folder then type: cd «new folder» and hit enter.
Tips to use CMD: Windows command line are not case sensitive. When working with a file or directory with a space, surround it in quotes. For example, My Documents would be «My Documents». When a file or directory is deleted in the command line, it is not moved into the Recycle bin. If you need help with any of command type /? after the command. For example, dir /? would give the options available for the dir command.