[Python-bugs-list] [ python-Bugs-516232 ] Windows os.path.isdir bad if drive only
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 12 Feb 2002 13:54:21 -0800
Bugs item #516232, was opened at 2002-02-11 14:50
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=516232&group_id=5470
Category: Extension Modules
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Charles I. Fuller (cifuller)
Assigned to: Nobody/Anonymous (nobody)
Summary: Windows os.path.isdir bad if drive only
Initial Comment:
It seems that most os functions recognize the Windows
drive letter without a directory as the current
directory on the drive, but os.path.isdir still
returns 0. If os.listdir('C:') returns data,
os.path.isdir('C:') should return 1 for consistency.
C:\folder_on_C>python
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.system('dir C:')
Volume in drive C has no label.
Volume Serial Number is E4C9-AD16
Directory of C:\folder_on_C
02/11/2002 05:29p <DIR> .
02/11/2002 05:29p <DIR> ..
02/11/2002 05:29p <DIR> subA
02/11/2002 05:29p <DIR> subB
0 File(s) 0 bytes
4 Dir(s) 22,126,567,424 bytes free
0
>>> os.listdir('C:')
['subA', 'subB']
>>> os.path.abspath('C:')
'C:\folder_on_C'
>>> os.path.isdir('C:')
0
----------------------------------------------------------------------
>Comment By: Charles I. Fuller (cifuller)
Date: 2002-02-12 13:54
Message:
Logged In: YES
user_id=211047
Responding to Tim's followup...
In this case the 'C:' is not the root drive, it is the
current dir on that drive. I noticed that os.path.abspath
was updated between 2.0 and 2.2 to recognize the current
dir.
It's an inconsistency that tripped me up already.
>>> os.path.isdir('C:')
0
>>> os.path.isdir(os.path.abspath('C:'))
1
The listdir has been working with drive specs (recognizing
the current dir) for a while. The abspath code must be
handling the drive-only input as a special case. The isdir
function should do the same for consistency.
There should at least be a warning in the docs...
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-02-11 15:16
Message:
Logged In: YES
user_id=31435
Sorry, this is how Microsoft's implementation of the
underlying stat() function works. "Root drive" paths must
be given with a trailing slash or backslash, else MS stat()
claims they don't exist. You'll see the same irritating
behavior in C code. Attempts to worm around it in the past
have introduced other bugs; see bug 513572 for a current
example.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=516232&group_id=5470