Trick To Demonstrate Current Functional Directory’s Complete Path With .BAT Command

A user implementing a “Batch-Command-Script” in (“.CMD or .BAT file extends) should know information about the current functional directory of the batch-script. Knowledge of the present working folder or directory in batch-commands is very helpful, as it confirms if the Script is either calling a command from the right directory path, or manipulating a folder or a program.

Next most significant utilization is in preserving and capturing the current folder for future usage as the script might alter the route during its course of action.

In reality, displaying and showing the present directory is simpler with the usage of pseudo-variables for “Cmd.exe” Environment-Variables.

Microsoft-Window has added “%CD%” pseudo-variables from Windows2000 versions onwards, which elaborates to the current functional directory.

For illustration, just utilize the following commands:

1) To exhibit current functional directory – “echo %CD%

2) To save and preserve the present functional directory wherein a file is situated for future usage after Change Directory (CD) to other directories to execute operations – “Currentdir=%CD%

The %Currentdir% is a Variable to stock the current functional folder, which can be utilized for future batch commands, such as altering back to its former directory.

However within the Windows 9x, the “%CD%” Pseudo-Variable does not exist. So, to get the current functional directory, utilize the following technique:

  • 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 final result variable “%cd%” will be brought back to the Batch Processing Session which comprises the present functional directory.


Please enter your comment!
Please enter your name here