RE: Bug in glob.glob for files w/o extentions in Windows

Discussion in 'Python' started by Tim Peters, Nov 30, 2003.

  1. Tim Peters

    Tim Peters Guest

    [Georgy Pruss]
    > On Windows XP glob.glob doesn't work properly for files without
    > extensions.


    I'd say it's Microsoft's dir that doesn't work properly in this case.

    > E.g. C:\Temp contains 4 files: 2 with extensions, 2
    > without.
    >
    > C:\Temp>dir /b *
    > aaaaa.aaa
    > bbbbb.bbb
    > ccccc
    > ddddd
    >
    > C:\Temp>dir /b *.
    > ccccc
    > ddddd


    Why on Earth should a pattern specifying a period match filenames that don't
    contain a period? Would you expect

    *x

    to match

    abc

    ? Nope. It's dir that special-cases the snot out of a period, not Python's
    glob. For cross-platform sanity, glob has to work the same way across
    platforms, and the Unixish shells have the obvious, explainable,
    unsurprising semantics here:

    $ ls *
    aaaaa.aaa bbbbb.bbb ccccc ddddd

    $ ls *.
    ls: *.: No such file or directory

    $ ls *.*
    aaaaa.aaa bbbbb.bbb

    > C:\Temp>python
    > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)]
    > on win32 Type "help", "copyright", "credits" or "license" for more
    > information.
    > >>> import glob

    >
    > >>> glob.glob( '*' )

    > ['aaaaa.aaa', 'bbbbb.bbb', 'ccccc', 'ddddd']
    >
    > >>> glob.glob( '*.' )

    > []


    > It looks like a bug.


    Good luck getting Microsoft to fix it <wink>.
    Tim Peters, Nov 30, 2003
    #1
    1. Advertising

  2. Tim Peters

    Duncan Booth Guest

    "Tim Peters" <> wrote in
    news::

    > ? Nope. It's dir that special-cases the snot out of a period, not
    > Python's glob.


    On that basis Python also 'special-cases the snot out of a period': try
    win32api.FindFiles('*.') to get the same behaviour as dir.

    More accurate would be to say that the operating system has consistent but
    weird behaviour, since it is below the application level that trailing dots
    are stripped from filenames and ignored from file patterns. The only way to
    avoid it on Windows is to retrieve all the filenames and then perform your
    own pattern matching on them.

    glob.glob is bypassing the operating system's filename matching to provide
    behaviour which is consistent across different operating systems, but
    inevitably this means that it doesn't match some platform's standard
    behaviour.

    --
    Duncan Booth
    int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
    "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
    Duncan Booth, Dec 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georgy Pruss
    Replies:
    15
    Views:
    723
    Tim Roberts
    Dec 1, 2003
  2. Sean Berry

    Question about glob.glob <--newbie

    Sean Berry, May 4, 2004, in forum: Python
    Replies:
    3
    Views:
    344
    David M. Cooke
    May 4, 2004
  3. Elbert Lev

    glob.glob unicode bug or feature

    Elbert Lev, Jul 31, 2004, in forum: Python
    Replies:
    5
    Views:
    392
    Neil Hodgson
    Aug 2, 2004
  4. Hitesh

    glob.glob output

    Hitesh, Mar 12, 2007, in forum: Python
    Replies:
    6
    Views:
    397
    Hitesh
    Mar 13, 2007
  5. billiejoex

    glob.glob standardization

    billiejoex, Jun 27, 2007, in forum: Python
    Replies:
    3
    Views:
    269
    Tim Roberts
    Jun 29, 2007
Loading...

Share This Page