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

Francis Avila francisgavila at yahoo.com
Sun Nov 30 04:30:49 EST 2003


Georgy Pruss wrote in message ...
>OK, you can call it not a bug, but different behavior.


That's true.  But calling dir's behavior "different" here is quite a
euphemism!

>It seems that in any case I'll have to extract 'nnn' by myself.
>Something like:
>
>      if mask.endswith('.'): # no extention implies actually no dots in
name at all
>        list = glob.glob( mask[:-1] )
>        list = filter( lambda x: '.' not in x, list ) # or [x for x in list
if '.' not in x]
>      else:
>        list = glob.glob( mask )
>


I don't understand where 'mask' is coming from.  If you want files with no
dots, just filter out those files:

filelist = [file for file in glob.glob('*') if '.' not in file]

Or you can use sets: symmetric difference of all files against the files
with dots.

If you're trying to recast glob in windows' image, you'll have to
specialcase '*.*' too.  And then what do you do if someone comes along who
*really* wants *only* names with dots in them!?

Trying to shoehorn windows-style semantics into glob is just braindead--the
windows semantics are wrong because dots are not special anymore.  For one
thing, we can have more than one of them, and they can be anywhere in the
filename.  Both were not true for DOS, whence windows inherited the *.*
nonsense.

Behold the awesome visage of the One True Glob (TM): (Not that I'm starting
a holy war or anything ;)
*.* -> Filename has a dot in it, and that dot cannot be the first or last
char.
       This is NOT the same as '*'!!
.*  -> Filename has a dot as the first character.
*.  -> Filename has a dot as the last character.
*   -> Gimme everything.
--
Francis Avila





More information about the Python-list mailing list