- Batch file : How to get current directory
- How to Change Directory in CMD | How to Use CD Command Win 10 [MiniTool News]
- Summary :
- What Is CD Command in Windows?
- How to Change Directory in CMD Windows 10
- How to Change Directory in CMD with CD Command
- Step 1. Open Windows Command Prompt Utility
- Step 2. How to Use CD Command in CMD to Change Directory
- Bottom Line
- ABOUT THE AUTHOR
- 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)
- BAT file to open CMD in current directory
- 18 Answers 18
Batch file : How to get current directory
Here’s a question from a blog reader.
“I need to write a batch script file which can traverse to different directories and do some operations on those directories. Once done, I need to come back to the original directory where the batch script started and do some more stuff. I need to get the initial starting directory and save it in a variable. My question is what’s the simple way to get the the directory from batch script. ”
Below is the answer for this question.
There is a very simple way to get the directory from a batch script file. CD environment variable stores the current directory of a command window session. Just run the command ‘echo %CD%’ and check it yourself.
Another way to do what the reader wanted would be to use the pushd and popd commands to traverse directories like a stack.
outputs blank empty line
If you traverse the flag of the 7th decimal variable. The channel of corresponding flag will stay static in the field of the command to enable what you need
How to create a batch file that can organise files into specific folders that have been downloaded from the internet.
Example; if I was to download a number of different file types such as a pdf, mp4,mp3, or an app, they would normally download into the download file by default. I would like to take the many different file types in the download folder and organise them into specific folders within my libraries by batching them. Can this be done?
You can download all the files into the default folder. Next, create a subfolder for each of the file type you have. Next, run the command below.
How to Change Directory in CMD | How to Use CD Command Win 10 [MiniTool News]
By Alisa | Follow | Last Updated March 04, 2021
Summary :
This tutorial gives a detailed guide on how to change directory in CMD (Command Prompt) in Windows 10 computer. Learn how to use CD command in Windows Command Prompt to access different directories and folders. FYI, MiniTool software designs a free data recovery software program allowing you to recover any deleted/lost files from Windows 10/8/7 computer and other storage devices.
Windows Command Prompt (cmd.exe) lets you do many things quickly on your Windows computer. Wonder how to change directory in CMD? You can use the CD command to easily do this.
What Is CD Command in Windows?
The CD command refers to “change directory”. It is a professional Windows Command Prompt change directory command. You can use CD command to easily change the current working directory in CMD in Windows 10, and open different directories or folders on your Windows 10 computer. Check how to use CD command to change directory in Command Prompt below.
How to Change Directory in CMD Windows 10
- Open elevated Command Prompt
- Use the CD command to change directory in CMD
How to Change Directory in CMD with CD Command
Step 1. Open Windows Command Prompt Utility
Before you use Command Prompt to change directory, you should enter into Command Prompt at first.
You can press Windows + R, type cmd, and press Ctrl + Shift + Enter to open elevated Command Prompt in Windows 10.
Step 2. How to Use CD Command in CMD to Change Directory
Then you can type CD command lines in CMD to change different directory or folder paths.
If you want to go to a specific directory, you can type cd + full directory path, e.g. cd C:\Program Files.
To open a particular folder, you can type cd + full folder path, e.g., cd C:\Program Files\office.
To go up a directory level you are currently working, you can type cd ..
To check the whole subdirectories and folders in the current directory, you can type dir command.
To go to the root level directory from any directory, you can type cd \.
To change the current drive, you can firstly type cd \ to go to the root directory, and then enter the drive letter followed by a colon to enter the target drive, e.g. I:.
To change the drive and directory at the same time, you can use CD and the /D switch simultaneously, e.g., cd /D I:\MiniTool Partition Wizard 11.
Bottom Line
Now you should know how to change directory in Command Prompt (CMD) by using CD command in Windows 10. You can easily access different directories or folders with CD command Windows in Command Prompt.
If you can’t find a file or folder in your Windows 10 computer, you may lost it or mistakenly deleted it, you can easily recover the file or folder with MiniTool Power Data Recovery.
MiniTool Power Data Recovery is a professional free data recovery program compatible with Windows 10/8/7. You can use this software to easily recover data from various data loss situations.
Namely, you can recover any deleted/lost files from Windows 10/8/7 computer, external hard drive, USB/thumb/pen drive, SD card, and more.
For the data loss due to mistaken file deletion, system crash and other computer system issues, hard drive failure, malware/virus infection, etc. you can use MiniTool Power Data Recovery to easily retrieve the lost files and data.
ABOUT THE AUTHOR
Position: Columnist
Alisa is a professional English editor with 4-year experience. She loves writing and focuses on sharing detailed solutions and thoughts for computer problems, data recovery & backup, digital gadgets, tech news, etc. Through her articles, users can always easily get related problems solved and find what they want. In spare time, she likes basketball, badminton, tennis, cycling, running, and singing. She is very funny and energetic in life, and always brings friends lots of laughs.
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.
BAT file to open CMD in current directory
I have many scripts which I interact with from the command line. Everytime I need to use them, I have to open a command line window and copy+paste and CD to the path to the directory they are in. This is tedious (they are in a rather deep file system, so typing out the full path is a pain, copy+paste is better but not much). I tried to create a .BAT file that I could double-click on that would open a new command-line window in the folder the .bat file exists in but it does not work. It opens a new window, but the working directory is not the directory that .bat file is in. Here’s what I’ve got after much googling (My cmd skills ain’t so great):
I know from when I used Linux that Konqueror had a «Command-line window here» feature, and that’s the effect I’m trying to get on Windows.
18 Answers 18
Create a file named open_dos_here.cmd with the following lines:
Put this file at any folder. Then, go to your Send To folder ( Win + E ; Alt + D ; shell:sendto ; Enter ). Create a shortcut to point to this open_dos_here.cmd
Then, in any folder, select any file or sub-folder. Right-click and select «Send To» and then select open_dos_here.cmd to open the DOS in that folder.
p1″ – Alvin SIU Dec 19 ’10 at 15:33
d1 is to extract only the drive letter of %1 (e.g. C:). This goes to C drive. The 2nd line cd to %
p1 which is the path of %1 (i.e. \myFolder). After going to this directory, simply call the cmd to open the DOS command prompt. – Alvin SIU Aug 23 ’14 at 9:12
you probably want to do this:
this will set your current directory to the directory you have the batch file in
dp0′ is simply the variable that holds the path the currently executing batch file is located in — therefore executing this command will take you to that directory (apparently this variable is only available from a batch file, which makes sense) – Chris Dec 15 ’10 at 15:51
dp0″ With the double-quotes? – Paul Tomasi Dec 19 ’10 at 3:59
dp0′ – Chris Jan 11 ’11 at 15:23
You can just enter cmd into the address bar in Explorer and it starts up in that path. Likewise for PowerShell.
There’s more simple way
As a more general solution you might want to check out the Microsoft Power Toy for XP that adds the «Open Command Window Here» option when you right-click: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
In Vista and Windows 7, you’ll get that option if you hold down shift and right-click (this is built in).
I’m thinking that if you are creating a batch script that relies on the Current Directory being set to the folder that contains the batch file, that you are setting yourself up for trouble when you try to execute the batch file using a fully qualified path as you would from a scheduler.
Better to add this line to your batch file too:
unless you are fully qualifying all of your paths.
The simplest command to do this:
start
You can always run this in command line to open new command line window in the same location. Or you can place it in your .bat file.
Most simple way in explorer is to Shift + right mouse click on the folder or on an empty space in the folder and click on Open command prompt here .
CMD will then start in that folder
I must say, I’m not sure if it works for Windows Vista and below, but it surely works for Windows 7, 8, 8.1 and 10.
Another solution is to use a shortcut file to cmd.exe instead of a batch file.
Edit the shortcut’s start in property to %
You achieve the same thing, except it has the Cmd icon (and you can change this).
Some people don’t like clicking on batch files without knowing what’s in them, and some corporate network drives have a ban on .bat files.
You could add a context menu entry through the registry:
Navigate in your Registry to HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell and create a key called «Command Prompt» without the quotes.
Set the default string to whatever text you want to appear in the right-click menu.
Create a new key within your newly created command prompt named «command,» and set the default string to
You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can’t be found.
- The changes should take place immediately. Right click a folder and your new menu item should appear.
Referring to answer of @Chris,
We can also go to parent directory of batch file and run commands using following
To understand working of command cd /d %
dp0.. please refer below link
A bit late to the game but if I’m understanding your needs correctly this will help people with the same issue.
Two solutions with the same first step: First navigate to the location you keep your scripts in and copy the filepath to that directory.
- Click «Start»
- Right-click «Computer» (or «My Computer)
- Click «Properties»
- On the left, click «Advanced System Settings»
- Click «Environment Variables»
- In the «System Variables» Box, scroll down and select «PATH»
- Click «Edit»
- In the «Variable Value» field, scroll all the way to the right
- If there isn’t a semi-colon (;) there yet, add it.
- Paste in the filepath you copied earlier.
- End with a semi-colon.
- Click «OK»
- Click «OK» again
- Click «OK» one last time
You can now use any of your scripts as if you were already that folder.
Second Solution: (can easily be paired with the first for extra usefulness)
On your desktop create a batch file with the following content.
This will open a command window like what you tried to do.