How to display the current directory path with cmd?

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.

1. Display the current directory path with the cd command

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.

cd
Display the current directory path with cmd using the cd command
Display the current directory path with cmd

2. Use the current directory path in a DOS variable

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.

%cd%

3. Script to display the current directory path dynamically

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

4. Display the cd command help

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:

cd /?

Conclusion on displaying the current Windows directory

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, i.e. the target. So this Windows tutorial explains how to get the current directory path with cmd. It is also possible to change the current directory to a new one with the cd command.