This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.listdir on empty strings. Inconsistent behaviour.
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: On Windows os.listdir('') -> cwd and os.listdir(u'') -> C:\
View: 5913
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, hannukoo, jvr, pitrou, rhettinger
Priority: high Keywords: needs review, patch

Created on 2003-10-05 10:50 by hannukoo, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
listdir.patch amaury.forgeotdarc, 2008-12-04 17:30
Messages (6)
msg18561 - (view) Author: Hannu Kankaanpää (hannukoo) Date: 2003-10-05 10:50
Behaviour tested in Python 2.3 (final) and 2.3.2 (final).
os.listdir('') and os.listdir(u'') have very different
behaviour across different OSes:

WinXP/WinNT:
os.listdir('') -- current dir (e.g. c:\\python)
os.listdir(u'') -- root dir (e.g. c:\\)

Win98
os.listdir('') -- root dir
os.listdir(u'') -- root dir

Redhat Linux 9.0
os.listdir('') -- OSError
os.listdir(u'') -- OSError

Particularly weird is the WinXP/WinNT behaviour that is
different between unicode and normal strings.

Suggestion for fix: Make os.listdir for empty strings 
always
raise an exception or always list the current working 
directory.
msg18562 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-10-28 06:29
Logged In: YES 
user_id=80475

Confirmed for WinME/98.  Also, the behavior changed from
Py2.2 where on WinME/98, it returned the root directory.
msg18563 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-10-28 06:31
Logged In: YES 
user_id=80475

Just, I believe this was your change.
msg18564 - (view) Author: Just van Rossum (jvr) * (Python triager) Date: 2003-10-28 08:26
Logged In: YES 
user_id=92689

I didn't touch the Win side of os.listdir() (it already supported 
unicode strings), so I'm pretty sure it isn't.
msg76901 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-12-04 17:30
This may become important when switching to python 3.0...

When passed str(''), FindFirstFileA is called with "*.*".
But when passed unicode(''), FindFirstFileW is called with L"\\*.*" !!!

Attached patch fixes (and tests) the problem. It was developed on 3.0,
but applies on all versions.
msg88497 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-05-29 02:46
Superseded by #5913.
History
Date User Action Args
2022-04-10 16:11:37adminsetgithub: 39373
2009-05-29 02:46:22benjamin.petersonsetstatus: open -> closed
resolution: duplicate
superseder: On Windows os.listdir('') -> cwd and os.listdir(u'') -> C:\
messages: + msg88497
2009-04-26 02:29:19ajaksu2setnosy: + pitrou, benjamin.peterson

type: behavior
versions: + Python 2.6, Python 3.0, Python 3.1, Python 2.7, - Python 2.3
2008-12-04 17:30:49amaury.forgeotdarcsetfiles: + listdir.patch
nosy: + amaury.forgeotdarc
messages: + msg76901
priority: normal -> high
keywords: + needs review, patch
stage: patch review
2003-10-05 10:50:30hannukoocreate