所有与 Windows 相关的问题都可以通过名为Command Prompt (CMD)的程序来解决。您可以向命令提示符(Command Prompt)提供可执行命令以执行各种管理功能。例如,cd或change directory命令用于更改您当前工作的目录路径。例如,命令 cd\windows\system32 会将目录路径切换到Windows文件夹中的(Windows)System32子文件夹。Windows cd 命令也称为chdir,可用于shell 脚本(shell scripts )和批处理文件(batch files). 在本文中,您将学习如何在Windows 10上更改(Windows 10)CMD中的目录。
如何在 Windows 10 上更改 CMD 中的目录(How to Change Directory in CMD on Windows 10)
什么是 Windows CWD 和 CD 命令?(What are Windows CWD and CD Command?)
当前工作目录(Current Working Directory)缩写为CWD是 shell 当前工作的路径。CWD必须保留其相对路径。操作系统的命令解释器包含一个通用命令,称为cd command Windows。
键入命令cd /? 在命令提示符窗口(Command Prompt window)中显示当前目录的名称或当前目录的更改。输入命令后,您将在命令提示符(Command Prompt)( CMD )中获得以下信息。
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
- 这..指定要更改到父目录。
- 键入CD 驱动器:( CD drive: )显示指定驱动器中的当前目录。
- 键入不带参数的CD以显示当前驱动器和目录。
- 使用/D开关更改当前驱动器 / 除了更改驱动器的当前目录。
除了命令提示符(Command Prompt)之外,Windows用户还可以使用 PowerShell 执行各种命令(PowerShell to execute various commands),如Microsoft docs here 中所述。
启用命令扩展时会发生什么?(What happens when Command Extensions are enabled?)
如果启用了命令扩展,则(Command Extensions)CHDIR更改如下:
- 当前目录字符串被转换为使用与磁盘名称相同的大小写。因此,如果磁盘上存在这种情况, CD C:\TEMP 实际上会将当前目录设置为 C:\Temp
-
CHDIR命令不将空格视为分隔符,因此可以将CD用于包含空格的子目录名称,即使不使用引号将其括起来。
例如:命令:cd \winnt\profiles\username\programs\start menu
与命令相同: cd “\winnt\profiles\username\programs\start menu”
继续(Continue)阅读下面的内容以修改/切换到目录或不同的文件路径。
方法 1:按路径更改目录(Method 1: Change Directory By Path)
使用命令cd + full directory path访问特定目录或文件夹。无论(Regardless)您在哪个目录中,这都会将您直接带到所需的文件夹或目录。请按照给定的步骤执行此操作:
1.在 CMD 中打开您要导航的目录(directory)或文件夹。(folder)
2. 右击地址栏(address bar),选择复制地址(Copy address),如图。
3. 现在,按Windows键,键入cmd,然后按Enter启动命令提示符。(Command Prompt.)
4. 在 CMD 中,键入cd(您复制的路径)(cd (the path you copied))并按回车(Enter ),如图所示。
这将打开您在Command Prompt(Command Prompt)中复制的路径的目录。
方法 2:按名称更改目录(Method 2: Change Directory By Name)
如何在CMD Windows 10中更改目录的另一种方法是使用 cd 命令启动您当前工作的目录级别:
1.如方法1所示打开命令提示符。(Command Prompt)
2.输入cd (你想去的目录)(cd (directory you want to go to))然后按 Enter(Enter)。
注意:(Note:)使用cd命令添加目录名称(directory name)以转到相应的目录。例如桌面(Desktop)
另请阅读:(Also Read:) 使用命令提示符 (CMD) 删除文件夹或文件(Delete a Folder or File using Command Prompt (CMD))
方法 3:转到父目录(Method 3: Go To Parent Directory)
当你需要上一个文件夹时,使用cd..命令。这是在Windows 10上更改CMD中的父目录的方法。
1.如前所述打开命令提示符。(Command Prompt)
2. 键入cd.. Â 并按Enter键。
注意:(Note:)在这里,您将从System文件夹重定向到Common Files 文件(Common Files)夹。
方法四:进入根目录(Method 4: Go To Root Directory)
有许多命令可以更改CMD Windows 10中的目录。一个这样的命令是更改到根目录:
注意:(Note:)无论您属于哪个目录,您都可以访问根目录。
1. 打开命令提示符,(Command Prompt, )输入cd /,然后按 Enter(Enter)。
2. 这里,Program Files的根目录是驱动器 C( drive C),这是 cd/ 命令带你去的地方。
另请阅读:(Also Read:) 如何从命令提示符 (cmd) 创建空文件(How to create empty files from the command prompt (cmd))
方法 5:更改驱动器(Method 5: Change Drive)
这是有关如何在Windows 10上更改(Windows 10)CMD中的目录的最简单方法之一。如果你想在CMD中更改驱动器,你可以通过输入一个简单的命令来实现。请按照下面列出的步骤执行此操作。
1. 按照方法 1(Method 1)中的说明转到命令提示符(Command Prompt)。
2. 键入驱动器(drive)号,后跟:(冒号(colon))以访问另一个驱动器,然后按Enter 键(Enter key)。
注意:(Note:)这里,我们从驱动器C:更改为驱动器D:,然后更改为驱动器E:
方法 6:同时更改驱动器和目录(Method 6: Change Drive & Directory Together)
如果您想同时更改驱动器和目录,则有一个特定的命令可以这样做。
1. 导航到方法 1(Method 1)中提到的命令提示符(Command Prompt)。
2. 输入cd /命令访问根目录。
3. 添加驱动器(drive letter)号,后跟:(冒号(colon))以启动目标驱动器。
例如,键入cd /D D:\Photoshop CC并按Enter键从驱动器C:转到D 驱动器中的(D drive.)Photoshop CC目录。
另请阅读:(Also Read:) [已解决]文件或目录已损坏且无法读取([SOLVED] The file or Directory is corrupted and unreadable)
方法 7:从地址栏打开目录(Method 7: Open Directory from Address Bar)
以下是直接从地址栏更改Windows 10上CMD目录的方法:(CMD)
1. 点击您要打开的目录的(directory)地址栏。(address bar )
2.输入cmd,按回车键( Enter key),如图。
3. 所选目录将在命令提示符中打开。
(Command Prompt.
)
方法8:查看目录内部(Method 8: View Inside the Directory)
也可以使用命令查看目录内部,如下:
1. 在命令提示符(Command Prompt)中,使用命令dir查看当前目录下的子文件夹和子目录。
2. 在这里,我们可以看到C:\Program Files夹中的所有目录。
受到推崇的(Recommended)
我们希望本指南对您有所帮助,并且您能够在 CMD Windows 10 中更改目录( change the directory in CMD Windows 10)。让我们知道您认为哪个 cd 命令Windows更有用。另外,如果您对本文有任何疑问或建议,请随时将它们放在评论部分。
How to Change Directory in CMD on Windows 10
All Windows-related issues might bе solved with a program named Command Prompt (CMD). You can feed the Command Prompt with executable commands to perform various administrative functions. For example, the cd or change directory command is used to change the directory path where you are working currently. For instance, the command cd\windows\system32 will switch the directory path to the System32 subfolder within the Windows folder. The Windows cd command is also called chdir, and it can be employed in both, shell scripts and batch files. In this article, you will learn how to change the directory in CMD on Windows 10.
How to Change Directory in CMD on Windows 10
What are Windows CWD and CD Command?
The Current Working Directory abbreviated as CWD is the path where the shell is currently working. The CWD is mandatory to retain its relative paths. The command interpreter of your Operating System holds a generic command called cd command Windows.
Type the command cd /? in the Command Prompt window to display the name of the current directory or changes in the current directory. After entering the command you will get the following information in Command Prompt (CMD).
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
- This .. 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 the current drive /in addition to changing the current directory for a drive.
In addition to Command Prompt, Windows users can also use PowerShell to execute various commands as explained by Microsoft docs here.
What happens when Command Extensions are enabled?
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 use CD into a subdirectory name that contains a space even without surrounding it with quotes.
For example: command: cd \winnt\profiles\username\programs\start menu
is same as the command: cd “\winnt\profiles\username\programs\start menu”
Continue reading below to modify/switch to the directories or to a different file path.
Method 1: Change Directory By Path
Use the command cd + full directory path to access a specific directory or folder. Regardless of which directory you are in, this would take you straight to the desired folder or directory. Follow the given steps to do so:
1. Open the directory or folder which you want to navigate in CMD.
2. Right-click on the address bar and then select Copy address, as shown.
3. Now, press the Windows key, type cmd, and hit Enter to launch Command Prompt.
4. In CMD, type cd (the path you copied) and press Enter as depicted.
This will open the directory which path you copied in Command Prompt.
Method 2: Change Directory By Name
Another way for how to change the directory in CMD Windows 10 is to use the cd command to launch a directory level where you are currently working:
1. Open Command Prompt as shown in Method 1.
2. Type cd (directory you want to go to) and hit Enter.
Note: Add the directory name with the cd command to go to that respective directory. e.g. Desktop
Also Read: Delete a Folder or File using Command Prompt (CMD)
Method 3: Go To Parent Directory
When you need to go one folder up, use the cd.. command. Here’s how to change the parent directory in CMD on Windows 10.
1. Open Command Prompt as earlier.
2. Type cd.. and press Enter key.
Note: Here, you will be redirected from the System folder to the Common Files folder.
Method 4: Go To Root Directory
There are many commands to change the directory in CMD Windows 10. One such command is to change to the root directory:
Note: You can access the root directory irrespective of which directory you belong to.
1. Open Command Prompt, type cd /, and hit Enter.
2. Here, the root directory for Program Files is drive C, which is where the cd/ command has taken you.
Also Read: How to create empty files from the command prompt (cmd)
Method 5: Change Drive
This is one of the easiest methods on how to change the directory in CMD on Windows 10. If you want to change the drive in CMD then, you can do so by typing a simple command. Follow the steps listed below to do so.
1. Go to Command Prompt as instructed in Method 1.
2. Type the drive letter followed by : (colon) to access another drive and press Enter key.
Note: Here, we are changing from drive C: to drive D: and then, to drive E:
Method 6: Change Drive & Directory Together
If you want to change the drive and directory together then, there is a particular command to do so.
1. Navigate to Command Prompt as mentioned in Method 1.
2. Type the cd / command to access the root directory.
3. Add the drive letter followed by : (colon) to launch the target drive.
For Example, type cd /D D:\Photoshop CC and press Enter key to go from drive C: to Photoshop CC directory in D drive.
Also Read: [SOLVED] The file or Directory is corrupted and unreadable
Method 7: Open Directory from Address Bar
Here’s how to change the directory in CMD on Windows 10 directly from the address bar:
1. Click on the address bar of the directory you want to open.
2. Write cmd and press Enter key, as shown.
3. The chosen directory will open in Command Prompt.
Method 8: View Inside the Directory
You can also use commands to view inside the directory, as follows:
1. In Command Prompt, use command dir to view the subfolders and subdirectories in your current directory.
2. Here, we can see all directories within C:\Program Files folder.
Recommended
We hope this guide was helpful and you were able to change the directory in CMD Windows 10. Let us know which cd command Windows do you think is more useful. Also, if you have any queries or suggestions regarding this article, then feel free to drop them in the comments section.