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.


Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

DOS get current directory - batch current directory - cmd current directory - dos batch current directory - dos current directory - batch get current directory - cmd current dir - batch file current path - bat current directory - dos get current path - cmd current path - batch current path - dos print current directory - get current directory in dos - windows batch current directory - batch file current directory - bat current path - echo current directory - get current directory batch - batch script current directory - dos command get current directory - show current directory - batch file current working directory - cmd get current path - cmd get current directory - bat get current path - current path cmd - current directory batch - windows current working directory - batch script directory - batch get current dir - batch working directory - current path batch file - current working directory windows - current path command - get current path in dos - .bat current directory - current directory cmd - dos show current directory - windows current working directory variable - dos batch change directory - windows command current directory - get current directory dos - batch get current folder - dos current path - set working directory batch file - show current directory in dos - storing current path in batch file - batch current - current path in cmd -