Display Current Folder
When using Command Prompt or batch files, it is often necessary to display the current directory (working directory).
By understanding the current directory, it becomes easier to manipulate files and folders, and work can be done more efficiently.
This article introduces the command to display the current directory and its applications.
Command to Display Current Directory
To display the current directory, use the cd
command.
Executing from Command Prompt
Executing from a Batch File
@echo off
setlocal
cd
endlocal
exit
Applying the Current Directory: Moving to the Temporary Directory
The cd
command displays the current working directory when no arguments are specified, but it can also be used to move the current directory by specifying arguments.
Here’s how to use the current directory to move to a temporary directory.
Executing from Command Prompt
Executing from a Batch File
@echo off
setlocal
cd %TEMP%
endlocal
exit
By using this method, you can easily move to a temporary directory and work on it.
Applying the Current Directory: Manipulating Files and Folders with Relative Paths
Using the current directory, you can manipulate files and folders with relative paths.
Here’s an example of how to move the sample.txt file in the current directory to the backup folder in the parent directory.
Executing from Command Prompt
Executing from a Batch File
@echo off
setlocal
set FILE=sample.txt
set DEST=..\backup\
move %FILE% %DEST%
endlocal
exit
By using the current directory, you can manipulate files and folders with relative paths. This allows you to create more concise and flexible commands and batch files.
Summary
This article introduced the command to display the current directory and its applications.