why is os.getcwd() printing the path in all caps on win2k?

Jimmy Retzlaff jimmy at retzlaff.com
Tue Jan 22 04:51:27 EST 2002


>> can anyone tell me why os.getcwd() prints out the path in all caps on
>> win2k at least?

It works fine on my Windows 2000 Server (SP2 w/IE6) using Python 2.2
(I'm quite sure it was the same on 2.1.1):

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getcwd()
'C:\\Python22'

There are several possible reasons within Windows for what you are
seeing including UI settings and the file system of your partition. One
possible reason for the difference is that your directories really are
all caps and Explorer is lying to you when you look at it there. Some
versions of Explorer (affected by version of Windows and version of IE)
default to displaying an upper case name like C:\PYTHON as C:\Python.
It's also possible that it's giving you the DOS/8.3 compatible name. Try
this:

>>> os.mkdir(r'c:\longDirectoryName')
>>> os.chdir(r'c:\longDirectoryName')
>>> os.getcwd()
'c:\\longDirectoryName'

Depending on how things are set up, you could see something like
'C:\\LONGDI~1' which is the DOS/8.3 compatible name. You can also see
the 8.3 names by doing "dir /x" at a command prompt.

If you get an exception in the above snippet, then it's likely that your
file system doesn't support long file names (and hence mixed case) at
all.

Jimmy




More information about the Python-list mailing list