Saturday 23 October 2010

How to Get the Current Directory for an Environment or Batch File Variable

Entering 'cd' by itself at the command line returns the current directory.

For example:

C:\sim>
C:\sim>cd
C:\sim

C:\sim>_

To set an environment variable at the command line:

C:\sim>set simdir=cd

To set an environment variable in a batch file:

set simdir=%cd%

To set a batch file variable in a batch file:

setlocal
set simdir=%cd%
@do stuff
endlocal

Notes
  • My reason for looking into this is to enable me to make my development portable and transferable. I recently started working with a friend and I needed a way to give him a copy of my system without requiring him to set anything up. I needed a batch file that could set up my environmental variables.

No comments:

Post a Comment