[Python-bugs-list] [Bug #113894] os.listdir(driveletter + ":") flawed on Win32

noreply@sourceforge.net noreply@sourceforge.net
Fri, 15 Sep 2000 00:44:31 -0700

Bug #113894, was updated on 2000-Sep-08 08:55
Here is a current snapshot of the bug.

Project: Python
Category: Modules
Status: Closed
Resolution: Fixed
Bug Group: Platform-specific
Priority: 7
Summary: os.listdir(driveletter + ":") flawed on Win32

Details: On windows NT the os.listdir() function doesn't correctly handle paths containing a drive specification, but no other directory spec. It incorrectly references the root directory on the specified drive rather than the current directory.
For example these two calls should return the same thing (the actual output has been slightly trimmed):

>>> import os
>>> os.listdir('c:')
['3DCube', 'Acrobat3', 'ADOBEAPP', ...]
>>> os.listdir('c:.')
['Capture', 'Catalog', ...]

The same problem shows up in os.glob, for example os.glob('d:*.py') will expand to all .py files in the root of drive d rather than the current directory.

One possible fix is that in posixmodule.c, function posix_listdir, the lines:
	strcpy(namebuf, name);
	if (namebuf[len-1] != '/' && namebuf[len-1] != '\\')
		namebuf[len++] = '/';
	strcpy(namebuf + len, "*.*");
should read:
	strcpy(namebuf, name);
	if (namebuf[len-1] != '/' && namebuf[len-1] != '\\' && namebuf[len-1] != ':')
		namebuf[len++] = '/';
	strcpy(namebuf + len, "*.*");


Date: 2000-Sep-12 06:19
By: gangli59

The bug show in glob.glob('d:*.py') is due to os.path.join joins 'd:', '*.py' to 'd:\\*.py' instead of 'd:*.py'

Date: 2000-Sep-15 00:03
By: tim_one

Changed Summary to be clearer.
I've made & tested the change as suggested (thanks!).
SourceForge CVS isn't working at the moment for me, though, so haven't yet checked it in.  Marked Fixed, but not yet Closed.

Date: 2000-Sep-15 00:44
By: tim_one

Checked in changes to posixmodule.c, and Closed.

For detailed info, follow this link: