List files without extension, was: Bug in glob.glob for files w/o extentions in Windows

Francis Avila francisgavila at yahoo.com
Mon Dec 1 01:31:10 CET 2003


Stein Boerge Sylvarnes wrote in message ...
>In article <bqcg7i$olj$03$1 at 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





More information about the Python-list mailing list