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]?
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.
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
set pattern [file join $directory *]
foreach fileName [glob -nocomplain $pattern] {
if {[string tolower [file extension $fileName]] == ".wav"} {
...
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