[Tutor] Adding the current working directory to the Windows path

Terry Carroll carroll at tjc.com
Wed Aug 23 22:11:49 CEST 2006

On Wed, 23 Aug 2006, travis mcgee wrote:

> Is there a simple way to append the os.getcwd() to the windows path
> statement?  I've tried variations of
> def createDirectory(self):
>         os.system('PATH %%PATH%%;%s;'%(here)) # here = os.getcwd()
> but it doesn't seem to work.  I don't get an error in IDLE, but if I open a
> command prompt, the path doesn't change.  I've googled around for a clue and
> looked through the documentation, but alas, I've had no luck.

First, this is a little bit outside my expertise, so I might be talking 
out my sleeve here.

I believe that modifications to the PATH system variable only modify the 
variable in the process making the modification, and probably processes 
spawned by that process.  

You can demonstrate this by opening two DOS windows.  Enter the command
"PATH" in both, and note they're the same.  Now, in one, enter the command
"PATH C:\"; then in both, enter the command "PATH" again.  You'll see that
only one has changed; the change in one session did nothing to the path in
the other.

I believe that the path for a new process is taken from the registry, in 
particular from 
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path

If you'd like a new process to use a new path, that's what I think you 
need to change; but it would apply to all new processes created 

More information about the Tutor mailing list