Bug in glob.glob for files w/o extentions in Windows
Georgy Pruss
see_signature__ at hotmail.com
Sat Nov 29 23:30:09 EST 2003
OK, you can call it not a bug, but different behavior.
I've found that the fnmatch module is the reason for that.
Here's other examples:
C:\temp>dir /b *.*
.eee
aaa.aaa
nnn
C:\temp>dir /b * # it's by def synonym for *.*
.eee
aaa.aaa
nnn
C:\temp>dir /b .*
.eee
C:\temp>dir /b *. # it looks strange too
.eee
nnn
C:\temp>python
>>> import glob
>>> glob.glob('*.*')
['aaa.aaa']
>>> glob.glob('*')
['aaa.aaa', 'nnn']
>>> glob.glob('.*')
['.eee']
>>> glob.glob('*.')
[]
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 )
G-:
More information about the Python-list
mailing list