Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Bug in glob.glob for files w/o extentions in Windows

Reply
Thread Tools

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

 
 
Tim Peters
Guest
Posts: n/a
 
      11-30-2003
[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>.


 
Reply With Quote
 
 
 
 
Duncan Booth
Guest
Posts: n/a
 
      12-01-2003
"Tim Peters" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> ? 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 http://www.velocityreviews.com/forums/(E-Mail Removed)
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java file extentions DGG Java 6 07-30-2005 12:38 PM
Question about Firefox extentions History Fan Firefox 3 06-20-2005 03:31 AM
Mozilla Extentions What's in a Name? Firefox 3 03-07-2005 03:49 AM
FireFox + extentions problems Konrad FLORCZAK Firefox 1 04-05-2004 09:34 PM
Bug in glob.glob for files w/o extentions in Windows Georgy Pruss Python 15 12-01-2003 04:04 AM



Advertisments