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

Alan Gauld alan.gauld at btinternet.com
Thu Aug 24 00:40:23 CEST 2006


> 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.  

PATH is an environment variable and therefore changing it only 
affects the current process environment. You need to change it 
at source which used to be in AUTOEXEC.BAT but I don't think 
that is the preferred place in Win2K/XP.

I'm sure there will be a registry setting somewhere and a hunt 
on MSDN will probably unearth it.

To write to the registry I usually use the WSH Shell object's
RegWrite() method. But there are raw API calls too.

Finally, ISTR that Windows actually changes the Environment 
globally via the os.putenv() call, it might be worth a try before 
messing with direct registry access!

Alan G.



More information about the Tutor mailing list