How to display the current directory path with cmd commands?
Command to display the current directory path, which is the folder where a cmd prompt is currently running. The MS-DOS command prompt is a text-based user interface that allows you to interact with a Windows computer or server. In order to display the current directory path with cmd, use the MS-DOS cd command. When using batch files, it becomes much useful to reuse the current location path. Especially when scripting dynamic actions using variables.
Display the current directory path using cmd
The cd command is one of the most used commands in MS-DOS. It is used to change directories. This command can be used to navigate the directory structure and find files on a computer or a server. From the command prompt program called cmd.exe in the system, simply se the cd command.
Use the current directory in a batch file using variables
In a batch file it is a very similar approach, the difference is that the current directory name is stored like a system variable, with two percentage symbols. From a batch script, i.e., a .bat file.
Script to display the current path dynamically using cmd
For example, use this simple example to assign a batch variable with the current directory path and display it to the screen. To use this example, simply copy and paste the code below to a BATCH file, for example DisplayDirectory.bat and execute it.
echo off rem the previous command is disabling echo to avoid all lines on the execution screen rem setting the variable with the current directory value set VarPath=%CD% rem displaying the variable on the prompt screen echo "The current folder is:" echo %VarPath% rem setting a 15 seconds timeout to let the prompt displayed timeout 15
The cd command is also useful to change the current drive and to navigate to the parent folder. To display the cd command help from within a command prompt, simply type this command:
It also possible to change the current directory to a new one with the cd command. It is available in MS-DOS, the Windows scripting tool. The syntax of the command is: cd [directory], where [directory] is the directory name or path to be changed to. To go further and check out more possibilities and examples. So this Windows tutorial explains how to get the current directory path with cmd.