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:
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:
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
The end result is a variable %CD% been returned to the batch processing session which contains the current working directory.
Share This Post
- Able2Extract Professional 11 Review – A Powerful PDF Tool
- How to Install Windows 10 & Windows 8.1 with Local Account (Bypass Microsoft Account Sign In)
- How to Upgrade CentOS/Red Hat/Fedora Linux Kernel (cPanel WHM)
- How to Install Popcorn Time Movies & TV Shows Streaming App on iOS (iPhone & iPad) With No Jailbreak
- Stream & Watch Free Torrent Movies & TV Series on iOS with Movie Box (No Jailbreak)
- Steganos Privacy Suite Free Download With Genuine License Series Key Code
- Windows 10 Insider Preview Build 18262 Released To Insiders in the Fast Ring and Skip Ahead
- Windows 10 Insider Preview Build 18267 – What’s New, Improved, Fixed, and Known issues
- O&O DiskImage Free Download With Genuine License Key Code
- Avira Prime Free 3-Months All-in-One Premium Services – Avira Antivirus Pro, Avira Phantom VPN Pro, Avira Identity Scanner Pro, Avira System Speedup Pro, Avira Software Updater Pro, Password Manager Pro