Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multiple glob patterns yield duplicate results

212 views
Skip to first unread message

Aric Bills

unread,
Oct 11, 2007, 9:17:27 PM10/11/07
to
Hi all,

I have a program that needs to work on both Windows and OS X. I'm
trying to accommodate the possibility of a case-sensitive filesystem
by using multiple patterns in a single call to [glob]:

set matches [glob -directory $directory *.wav *.WAV]

But on Windows XP in both Tcl 8.4.16 and 8.5b1, the result of the
above code contains two instances of each matching file. I realize I
could get rid of these with [lsort -unique], but I'm surprised to see
the duplicates in the first place. Is that the intended behavior of
[glob]?

Ron Fox

unread,
Oct 12, 2007, 5:29:17 AM10/12/07
to
It makes sense on windows because .wav and .WAV are identical at the
file system level, and because you are asking glob to give you the
result of two matches. How about:

glob -directory $directory {*.[wW][aA][vV]}


That's a more general case insenstive search and will, since you are
only searching for a single pattern most likely only give you one match.

Aric Bills

unread,
Oct 12, 2007, 1:34:13 PM10/12/07
to
On Oct 12, 1:29 am, Ron Fox <f...@nscl.msu.edu> wrote:
> It makes sense on windows because .wav and .WAV are identical at the
> file system level, and because you are asking glob to give you the
> result of two matches.

The present behavior makes sense, in the sense that it's obvious
what's happening and why. But I can't imagine a situation where
someone would want duplicate results from a call to [glob]. If each
pattern results in a set of matches, the most useful result would be
the union of these sets.

> How about:
>
> glob -directory $directory {*.[wW][aA][vV]}
>
> That's a more general case insenstive search and will, since you are
> only searching for a single pattern most likely only give you one match.

Yeah, I could go this route. It's not terribly elegant, but neither
is my current approach :) And it does have the advantages you
describe.

The ideal solution to this problem would be a -nocase flag; I haven't
looked at the Tcl source to see how feasible that would be.

Thanks for your reply.
Aric

Russell Bell

unread,
Oct 18, 2007, 8:01:27 PM10/18/07
to
Another technique:

set pattern [file join $directory *]
foreach fileName [glob -nocomplain $pattern] {
if {[string tolower [file extension $fileName]] == ".wav"} {
...

Andrew Mangogna

unread,
Oct 18, 2007, 9:26:09 PM10/18/07
to
Aric Bills wrote:

One way to achieve set-like behavior is to use struct::set from Tcllib, as
in:

package require struct::set

set wavfiles [struct::set union [glob *.wav *.WAV]]


--
Andrew Mangogna

0 new messages