Changing Working Directory in Windows

Andy Gimblett gimbo at ftech.net
Mon Mar 11 08:41:20 EST 2002


On Mon, Mar 11, 2002 at 01:28:53PM +0000, nrk at cmcorp.com wrote:
> I'm brand new to Python.  Can someone tell me how to change a working
> directory in a script on a Windows system?

Use os.chdir()

> What does the pathname specification look like?

Like any other pathname specification on your platform.  I use linux
so it's like '/usr/local/bin', but since you're on Windows, I guess
it'd be something like 'C:\WIN32\SYSTEM\' or similar?

What does os.getcwd() return?  That'll give you a clue as to the
format you should use.  On my box:

>>> import os
>>> os.getcwd()
'/home/gimbo'

Also, check out os.path.split() and os.path.join() (and all the other
os.path calls!) for manipulating pathnames in a platform-sensitive
manner.

> Can I use an absolute path name when referring to a file?

Absolutely.  :-)

For more information on these topics, see:

  http://www.python.org/doc/current/lib/module-os.html
  http://www.python.org/doc/current/lib/os-file-dir.html
  http://www.python.org/doc/current/lib/module-os.path.html

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list