Using Absolute and Relative Paths
Absolute Path
An absolute path starts with the root directory and specifies the exact location of the folder. To open a folder using an absolute path, follow these steps:
- In a new command prompt window, type “cd” followed by a space.
- Enter the absolute path of the folder you want to open and press Enter.
For example, to open the “My Documents” folder in the “Documents and Settings” directory, you would type the following command:
“`
cd C:\Documents and Settings\YOUR_USER_NAME\My Documents
“`
Relative Path
A relative path starts from the current directory and specifies the location of the folder relative to it. To open a folder using a relative path, follow these steps:
- In a new command prompt window, type “cd” followed by a space.
- Enter the relative path of the folder you want to open and press Enter.
For example, if you are in the “Documents” directory and want to open the “My Documents” folder, you would type the following command:
“`
cd My Documents
“`
You can also use the following table to help you understand the difference between absolute and relative paths:
| Path Type |
Example |
Description |
| Absolute |
C:\Documents and Settings\YOUR_USER_NAME\My Documents |
Specifies the exact location of the folder from the root directory |
| Relative |
My Documents |
Specifies the location of the folder relative to the current directory |
Using the “| more” Command for Paging Through Results
When you execute a command that produces a large amount of output, the results may scroll off the screen too quickly for you to read them. To prevent this, you can use the “| more” command to paginate the results. The “| more” command will pause the output after each screenful of data, and you can press the Enter key to continue scrolling through the results.
For example, the following command will list the contents of the directory “C:\Windows\System32” and pause after each screenful of results:
dir C:\Windows\System32 | more
You can also use the “| more” command to create a custom pager. For example, the following command will create a pager that pauses after every 10 lines of output:
dir C:\Windows\System32 | more /10
You can also use the “| more” command to specify the size of the window in which the output is displayed. For example, the following command will create a pager that displays 20 lines of output at a time:
dir C:\Windows\System32 | more /20
The following table summarizes the options that you can use with the “| more” command:
| Option |
Description |
| /10 |
Pauses after every 10 lines of output |
| /20 |
Pauses after every 20 lines of output |
| /np |
Disables pausing and scrolls continuously |
| /s |
Displays the output in a single screenful |
| /t |
Displays the output in a table format |
Opening a Folder Using the “dir” Command
This command lists the contents of a specified folder or directory. It can be used in the following format:
“`
dir [path]
“`
Where:
`path` is the full path to the folder you want to open.
For example, to open the “My Documents” folder, you would use the following command:
“`
dir C:\Users\yourusername\Documents
“`
Using the /w Switch
The `/w` switch specifies that the contents of the folder should be displayed in a wide format. This makes it easier to read the file names and sizes.
The following command would open the “My Documents” folder in a wide format:
“`
dir C:\Users\yourusername\Documents /w
“`
Using the /s Switch
The `/s` switch specifies that the contents of the folder and all its subfolders should be displayed.
The following command would open the “My Documents” folder and all its subfolders:
“`
dir C:\Users\yourusername\Documents /s
“`
Using the /a Switch
The `/a` switch specifies that the attributes of the files and folders in the directory should be displayed.
The following command would open the “My Documents” folder and display the attributes of the files and folders:
“`
dir C:\Users\yourusername\Documents /a
“`
Using the /r Switch
The `/r` switch specifies that the subdirectories should be sorted in reverse order.
The following command would open the “My Documents” folder and sort the subdirectories in reverse order:
“`
dir C:\Users\yourusername\Documents /r
“`
Using the /b Switch
The `/b` switch specifies that only the file names should be displayed, without any other information.
The following command would open the “My Documents” folder and display only the file names:
“`
dir C:\Users\yourusername\Documents /b
“`
Opening a Folder Using the “Explorer” Command
The explorer command in cmd is used to open a specified folder in Windows File Explorer. To use this command, follow these steps:
1. Open Command Prompt
Press the Windows key + R to open the Run dialog box. Type “cmd” and press Enter to open Command Prompt.
2. Navigate to the Desired Folder
Use the cd command to navigate to the folder you want to open. For example, to navigate to the Desktop folder, type the following command:
cd %userprofile%\Desktop
3. Use the “Explorer” Command
Type the following command to open the current folder in Windows File Explorer:
explorer .
4. Open a Specific Folder
To open a specific folder, specify the full path to the folder after the explorer command. For example, to open the Documents folder, type the following command:
explorer %userprofile%\Documents
5. Open Multiple Folders
To open multiple folders at once, separate the folder paths with spaces. For example, to open the Documents and Pictures folders, type the following command:
explorer %userprofile%\Documents %userprofile%\Pictures
6. Open a Hidden Folder
To open a hidden folder, use the /root parameter with the explorer command. For example, to open the AppData folder, type the following command:
explorer /root %userprofile%\AppData
7. Advanced Options
The explorer command offers several advanced options that can be used to customize the behavior of the opened folder. These options include:
| Option |
Description |
| /n |
Opens the folder in a new window |
| /e |
Selects all files and folders in the opened folder |
| /select |
Selects the specified file or folder in the opened folder |
Opening a Folder Using the “%cd%” Variable
The “%cd%” variable in Command Prompt represents the current working directory. By utilizing this variable, you can effortlessly open the current folder in File Explorer or any other file management program.
Steps
-
Navigate to the Target Folder: Use the "cd" command to navigate to the folder you wish to open. For instance, if the folder is located in "C:\Users\John\Documents\Folder", enter "cd C:\Users\John\Documents\Folder".
-
Display the Current Directory: Type "%cd%" in Command Prompt. This command will display the full path of the current working directory.
-
Copy the Path: Right-click within the "%cd%" output and select "Copy". This will copy the folder’s path to the clipboard.
-
Open File Explorer: Press "Windows Key + E" to open File Explorer.
-
Paste the Path into the Address Bar: Click on the address bar at the top of File Explorer and press "Ctrl + V" to paste the copied path.
-
Press Enter: Once the path is pasted, press "Enter". This will navigate File Explorer to the desired folder.
-
Open with an Alternate Program: If you prefer to open the folder with a different file management program, such as Total Commander, use the following syntax:
start "" "C:\Path\to\TotalCommander.exe" "%cd%"
- Create a Shortcut: To create a shortcut that opens the current folder in File Explorer, navigate to the folder and enter the following command:
mklink "Shortcut Name" "%cd%"
- Customize Shortcut Properties: Right-click the shortcut and select "Properties". In the "Target" field, modify "explorer.exe" to the path of your preferred file management program. Additionally, you can change the "Start in" field to the specific folder within the current working directory that you wish to open.
| Command |
Description |
| %cd% |
Displays the current working directory |
| start “” “C:\Path\to\TotalCommander.exe” “%cd%” |
Opens the current folder in Total Commander |
| mklink “Shortcut Name” “%cd%” |
Creates a shortcut that opens the current folder in File Explorer |
Opening a Folder Using the “subst” Command
The “subst” command is a powerful tool that allows users to create virtual drives and assign them to physical folders on their computer. This can be useful for accessing files and folders more easily or for mapping network drives to local folders. To open a folder using the “subst” command, follow these steps:
- Open the Command Prompt. You can do this by pressing Windows Key + R and typing “cmd”.
- Type the following command, replacing “X:” with the drive letter you want to assign to the folder:
subst X: [path to folder]
For example, to assign the drive letter “X:” to the folder “C:\Users\John Doe\Documents”, you would type:
subst X: C:\Users\John Doe\Documents
- Press Enter.
You can now access the folder using the assigned drive letter. For example, if you assigned the drive letter “X:” to the folder “C:\Users\John Doe\Documents”, you can now access the folder by typing “X:” in the Command Prompt or in the File Explorer address bar.
To remove the virtual drive, simply type the following command:
subst X: /D
where “X:” is the drive letter you want to remove.
How to Open a Folder in CMD
The command prompt (CMD) is a powerful tool that can be used to perform a variety of tasks on a computer. One of the most common tasks is to open a folder. There are several ways to do this, but the most common is to use the “cd” command.
To open a folder using the “cd” command, simply type the following command into the command prompt:
“`
cd path_to_folder
“`
For example, to open the folder “My Documents”, you would type the following command:
“`
cd C:\Users\YourUsername\Documents
“`
Once you have opened the folder, you can use the “dir” command to view the contents of the folder.
People Also Ask
How do I open a folder in CMD using a shortcut?
You can create a shortcut to a folder in CMD by using the “mklink” command. To do this, simply type the following command into the command prompt:
“`
mklink /d shortcut_name path_to_folder
“`
For example, to create a shortcut to the folder “My Documents” on the desktop, you would type the following command:
“`
mklink /d desktop_shortcut C:\Users\YourUsername\Documents
“`
How do I open a folder in CMD using a batch file?
You can create a batch file that will open a folder in CMD. To do this, simply create a new text file and type the following command into it:
“`
cd path_to_folder
“`
For example, to create a batch file that will open the folder “My Documents”, you would type the following command into the text file:
“`
cd C:\Users\YourUsername\Documents
“`
Once you have saved the batch file, you can double-click on it to open the folder in CMD.