473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

On Windows XP glob.glob doesn't work properly for files without extensions.
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

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.

Georgy
--
Georgy Pruss
E-mail: 'ZDAwMTEyMHQwMzMwQGhvdG1haWwuY29t\n'.decode('base6 4')
Jul 18 '05 #1
15 3050
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-:
Jul 18 '05 #2
On Sun, 30 Nov 2003 03:47:38 GMT, in article
<news:uL*********************@twister.southeast.rr .com>, Georgy Pruss
wrote:
On Windows XP glob.glob doesn't work properly for files without extensions.
E.g. C:\Temp contains 4 files: 2 with extensions, 2 without.
[...]
C:\Temp>dir /b *.
ccccc
ddddd
This is standard Windows behavior. It's compatible with CP/M and therefore
MS-DOS, and Microsoft has preserved this behavior in all versions of
Windows.

Did you ever poke around in the directory system in a FAT partition
(without VFAT)? You'll find that every file name is exactly 11 characters
long and "." is not found in any part of any file name in any directory
entry.

It's bizarre but that's the way it works. If you try

dir /b *

does cmd.exe list only files without extensions?
glob.glob( '*.' )

[]


glob provides "Unix style pathname pattern expansion" as documented in the
_Python Library Reference_: If there's a period (".") in the pattern, it
must match a period in the filename.
It looks like a bug.


No, it's proper behavior. It's Windows that's (still) screwy.
Jul 18 '05 #3

"Jules Dubois" <bo***@invalid.tld> wrote in message news:nj*****************************@40tude.net...
| On Sun, 30 Nov 2003 03:47:38 GMT, in article
| <news:uL*********************@twister.southeast.rr .com>, Georgy Pruss
| wrote:
|
| > On Windows XP glob.glob doesn't work properly for files without extensions.
| > E.g. C:\Temp contains 4 files: 2 with extensions, 2 without.
| > [...]
| > C:\Temp>dir /b *.
| > ccccc
| > ddddd
|
| This is standard Windows behavior. It's compatible with CP/M and therefore
| MS-DOS, and Microsoft has preserved this behavior in all versions of
| Windows.

That's what I meant, wanted and liked.

C'mon guys, I don't care if it's FAT, NTFS, Windows, Linux, VMS or whatever.
All I wanted was to get files w/o dots in their names (on my computer :)).
I did it and I can do it on any system if I need.
| Did you ever poke around in the directory system in a FAT partition
| (without VFAT)? You'll find that every file name is exactly 11 characters
| long and "." is not found in any part of any file name in any directory
| entry.
|
| It's bizarre but that's the way it works. If you try
|
| dir /b *
|
| does cmd.exe list only files without extensions?

By definition it's the same as *.* if my memory serves me right.
| >>>> glob.glob( '*.' )
| > []
| >
|
| glob provides "Unix style pathname pattern expansion" as documented in the
| _Python Library Reference_: If there's a period (".") in the pattern, it
| must match a period in the filename.
|
| > It looks like a bug.
|
| No, it's proper behavior. It's Windows that's (still) screwy.

I see.
Show the world a perfect OS and you'll be a billionaire.

G-:
Jul 18 '05 #4
On Sun, 30 Nov 2003 06:18:36 GMT, in article
<news:0Z********************@twister.southeast.rr. com>, Georgy Pruss wrote:
"Jules Dubois" <bo***@invalid.tld> wrote in message news:nj*****************************@40tude.net...
| On Sun, 30 Nov 2003 03:47:38 GMT, in article
|
C'mon guys, I don't care if it's FAT, NTFS, Windows, Linux, VMS or whatever.
All I wanted was to get files w/o dots in their names (on my computer :)).
I was just pointing out the reason for the behavior.
| dir /b *
|
| does cmd.exe list only files without extensions?

By definition it's the same as *.* if my memory serves me right.
I'm sure ".*" was the same as "*.*". Win2k's cmd.exe won't run under Wine,
so I couldn't test "*".
| No, it's proper behavior. It's Windows that's (still) screwy.

Show the world a perfect OS and you'll be a billionaire.


We agree, then, that every operating system has its good points and its bad
points. (I guess we don't agree on whether "*." should or shouldn't match
files without periods in their name.)
Jul 18 '05 #5

"Jules Dubois" <bo***@invalid.tld> wrote in message news:b6*****************************@40tude.net...
|
| We agree, then, that every operating system has its good points and its bad
| points. (I guess we don't agree on whether "*." should or shouldn't match
| files without periods in their name.)

Anyway, "*." is not a bad DOS convention to select files w/o extention, although
it comes from the old 8.3 name scheme. BTW, how can you select files w/o
extention in Unix's shells?

G-:

Jul 18 '05 #6
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

Jul 18 '05 #7
Anyway, "*." is not a bad DOS convention to select files w/o extention, although
it comes from the old 8.3 name scheme. BTW, how can you select files w/o
extention in Unix's shells?

The same way as in Python:
filelist = [file for file in glob.glob('*') if '.' not in file]
Shell:
ls|grep -v [.]
Making up special conventions is not the Python way.

-- Serge.
Jul 18 '05 #8
Georgy Pruss wrote:
Anyway, "*." is not a bad DOS convention to select files w/o extention,
although it comes from the old 8.3 name scheme. BTW, how can you select
files w/o extention in Unix's shells?


ls -I*.*

The -I option tells the ls command what *not* to show.

Peter
Jul 18 '05 #9
Francis Avila wrote:
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.


Note that Bash doesn't behave like this either: * does not give
everything, rather it gives everything not starting with a dot. In Bash,
* really means: [!.]*

yours,
Gerrit.

--
102. If a merchant entrust money to an agent (broker) for some
investment, and the broker suffer a loss in the place to which he goes, he
shall make good the capital to the merchant.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #10
Gerrit Holl wrote in message ...
Francis Avila wrote:
Note that Bash doesn't behave like this either: * does not give
everything, rather it gives everything not starting with a dot. In Bash,
* really means: [!.]*

That behavior can be modified with the 'dotglob' shell option:

$shopt -s dotglob
$echo *
a .b b .c d ...

--
Francis Avila
Jul 18 '05 #11
In article <bq*************@news.t-online.com>, Peter Otten wrote:
Georgy Pruss wrote:
Anyway, "*." is not a bad DOS convention to select files w/o extention,
although it comes from the old 8.3 name scheme. BTW, how can you select
files w/o extention in Unix's shells?
ls -I*.*

The -I option tells the ls command what *not* to show.

That's non-standard gnu ls behaviour, I think. (Tested on OpenBSD and SunOS)
Peter


--
regards/mvh
Stein B. Sylvarnes
st*************@student.uib.no
Jul 18 '05 #12

Stein Boerge Sylvarnes wrote in message ...
In article <bq*************@news.t-online.com>, Peter Otten wrote:
Georgy Pruss wrote:
Anyway, "*." is not a bad DOS convention to select files w/o extention,
although it comes from the old 8.3 name scheme. BTW, how can you select
files w/o extention in Unix's shells?


In Windows, how do you create a file with a dot as the last character? In
Unix you can do this, because a dot is just another character in the
filename. It's because you can't do this in Windows that *. is unambiguous.
ls -I*.*

The -I option tells the ls command what *not* to show.

That's non-standard gnu ls behaviour, I think. (Tested on OpenBSD and

SunOS)
for N in $(ls -1 | grep -v '\.'); echo $N; done

Not positively sure that the -1 option is posix, but it's at least in
OpenBSD and SunOS (in fact, it's the default when output is not to a
terminal).

Bash also has an extglob option:

$ shopt -s extglob dotglob
$ ls -1 *
a
..b
c.c
d.
$ echo !(*.*)
a

There's also @(), ?(), *(), +(). You can use multiple patterns within the
parens by joining with '|'.
--
Francis Avila

Jul 18 '05 #13
On Sun, 30 Nov 2003 08:59:55 GMT, in article
<news:fk********************@twister.southeast.rr. com>, Georgy Pruss wrote:
"Jules Dubois" <bo***@invalid.tld> wrote in message news:b6*****************************@40tude.net...
| (I guess we don't agree on whether "*." should or shouldn't match
| files without periods in their name.)

Anyway, "*." is not a bad DOS convention to select files w/o extention, although
it comes from the old 8.3 name scheme. BTW, how can you select files w/o
extention in Unix's shells?


Touche.
Jul 18 '05 #14
In article <0Z********************@twister.southeast.rr.com >,
"Georgy Pruss" <se*************@hotmail.com> wrote:

"Jules Dubois" <bo***@invalid.tld> wrote in message news:nj*****************************@40tude.net...
| On Sun, 30 Nov 2003 03:47:38 GMT, in article
| <news:uL*********************@twister.southeast.rr .com>, Georgy Pruss
| wrote:
|
| > On Windows XP glob.glob doesn't work properly for files without extensions.
| > E.g. C:\Temp contains 4 files: 2 with extensions, 2 without.
| > [...]
| > C:\Temp>dir /b *.
| > ccccc
| > ddddd
|
| This is standard Windows behavior. It's compatible with CP/M and therefore
| MS-DOS, and Microsoft has preserved this behavior in all versions of
| Windows.

That's what I meant, wanted and liked.

C'mon guys, I don't care if it's FAT, NTFS, Windows, Linux, VMS or whatever.
All I wanted was to get files w/o dots in their names (on my computer :)).
I did it and I can do it on any system if I need.


Looks like you need os.path.glob(), which doesn't exist, yet.

Regards. Mel.
Jul 18 '05 #15
"Georgy Pruss" <se*************@hotmail.com> wrote:

"Jules Dubois" <bo***@invalid.tld> wrote in message news:nj*****************************@40tude.net...
|
| It's bizarre but that's the way it works. If you try
|
| dir /b *
|
| does cmd.exe list only files without extensions?

By definition it's the same as *.* if my memory serves me right.


Actually, truth being stranger than fiction, the NT-based systems and the
16-bit systems (95/98/ME) will give you different answers to this
question...
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eric | last post by:
Pythonistas, I seem at a loss for a List Comprehension syntax that will do what I want. I have a list of string position spans: >>> breaks the first pair representing: someString
4
by: Python Dunce | last post by:
I've run into an issue with glob and matching filenames with brackets '' in them. The problem comes when I'm using part of such a filename as the path I'm passing to glob. Here's a trimmed down...
3
by: seannakasone | last post by:
i'm looking for something like glob.glob() that traverses sub-directories. is there anything like that? i guess i'm looking for something to replace the unix find command.
6
by: Hitesh | last post by:
import string import os f = open ("c:\\servername.txt", 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog #print lineLog for l in lineLog:
5
by: PythonNewbie | last post by:
Hello, so I needed to write a quick code that lets me merge whole bunch of text files in a given folder into one text file. So, I wrote this up after reading about glob import glob...
8
by: mark.bergman | last post by:
I am porting from Digital Unix to Linux (RHEL 4), and am seeing a difference in the return value of glob(). Given a non-existant directory "/tmp/a", and the following line of code: result =...
1
by: crybaby | last post by:
when I do this in my python code and run it in windows xp, it creates ctemp/..../.../.../../ so on and creates file t. Not file starting with the name complist and ending with .txt...
5
by: jo3c | last post by:
hi everyone happy new year! im a newbie to python i have a question by using linecache and glob how do i read a specific line from a file in a batch and then insert it into database? because...
4
by: John [H2O] | last post by:
I have a glob.glob search: searchstring = os.path.join('path'+'EN*') files = glob.glob(searchstring) for f in files: print f ___ This returns some files:
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.