Show Current Working Folder or Directory Full Path in Batch Command Script
When executing a batch command script (in .cmd or .bat file extension), sometimes it’s useful to get to know the current working directory of the batch script. Knowing the current directory or working folder in batch command is useful to ensure that the script is calling command or program at correct path, or manipulation of file and folder is done at valid destination when using relative path. Another important usage is to capture and save the current directory for later use, and the script may change the path during its course.
In fact, the showing and displaying of current directory is easy with the use of pseudo-variable for cmd.exe environment variables. From Windows 2000 onwards, Microsoft Windows has added %CD% pseudo-variable that expands to the current working directory.
For example, to display current working directory, just use the following command:
Echo %CD%
To save and store the current directory where a file is located for later use after change directory (cd) to other folder to perform other operations, use the following commands:
Set CURRENTDIR=%CD%
The %CURRENTDIR% variable to store the current working directory, which can be used in later batch commands, which as changing back to this previous directory.
In Windows 9x, the %CD% pseudo-variable is not existed. To get the current directory, use the following trick:
CD | Time | Find ":\" > Temp1.Bat
Echo Set CD=%%4 %%5 %%6 %%7 %%8 %%9 > Enter.Bat
Call Temp1.Bat
Del Temp1.Bat
Del Enter.Bat
The end result is a variable %CD% been returned to the batch processing session which contains the current working directory.
Related posts:
- Script to Backup Current Start State (Startup Type) of Windows Services
- Open Elevated Command Prompt Window Here as Administrator at Current Folder Directly in Vista Windows Explorer
- Reveal and Access to Windows Vista Hidden Context-Sensitive (Right Click) Menu Item – Open Command Prompt Here & Copy as Path
- Windows Vista and Server 2008 Services Optimization (with Batch Command Script Optimizer)
- TimerLock Automated Batch Install Script for TimerStop Driver v2a and Windows Vista Activation 2099 Crack





Hello,
I sometimes need to mount some drive paths as a virtual drive and just came up with to create a batch file that I can copy to those folders to run everytime needed.
I tried the following commands in batch files but none of them had worded!
subst o: %~dp0
subst o: path
could you please help to fix this?
is there a way to write a command that also check drive letters first and make sure that it's not a used one?