Skip to content

os.listdir on empty strings. Inconsistent behaviour. #39373

Closed

Description

@hannukoo
mannequin
BPO 818059
Nosy @rhettinger, @amauryfa, @pitrou, @benjaminp
Superseder
  • bpo-5913: On Windows os.listdir('') -> cwd and os.listdir(u'') -> C:</li>
  • Files
  • listdir.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-05-29.02:46:22.064>
    created_at = <Date 2003-10-05.10:50:30.000>
    labels = ['type-bug', 'library']
    title = 'os.listdir on empty strings. Inconsistent behaviour.'
    updated_at = <Date 2009-05-29.02:46:22.062>
    user = 'https://bugs.python.org/hannukoo'

    bugs.python.org fields:

    activity = <Date 2009-05-29.02:46:22.062>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-05-29.02:46:22.064>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2003-10-05.10:50:30.000>
    creator = 'hannukoo'
    dependencies = []
    files = ['12222']
    hgrepos = []
    issue_num = 818059
    keywords = ['patch', 'needs review']
    message_count = 6.0
    messages = ['18561', '18562', '18563', '18564', '76901', '88497']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'jvr', 'amaury.forgeotdarc', 'hannukoo', 'pitrou', 'benjamin.peterson']
    pr_nums = []
    priority = 'high'
    resolution = 'duplicate'
    stage = 'patch review'
    status = 'closed'
    superseder = '5913'
    type = 'behavior'
    url = 'https://bugs.python.org/issue818059'
    versions = ['Python 2.6', 'Python 3.0', 'Python 3.1', 'Python 2.7']

    Activity

    1. hannukoo commented on Oct 5, 2003

      hannukoomannequin
      MannequinAuthor

      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.

    2. added
      stdlib
      on Oct 5, 2003
    3. rhettinger commented on Oct 28, 2003

      @rhettinger
      Contributor

      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.

    4. rhettinger commented on Oct 28, 2003

      @rhettinger
      Contributor

      Logged In: YES
      user_id=80475

      Just, I believe this was your change.

    5. jvr commented on Oct 28, 2003

      jvrmannequin
      Mannequin

      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.

    6. amauryfa commented on Dec 4, 2008

      @amauryfa
      Contributor

      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.

    7. added
      type-bug
      on Apr 26, 2009
    8. benjaminp commented on May 29, 2009

      @benjaminp
      Contributor

      Superseded by bpo-5913.

    9. transferred this issue fromon Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions