What's up with "Dir.glob"?

Hi,
I’m having a hard time understanding why a simple Dir.glob sequence
isn’t working. I need to interrogate a directory for files that are
prefixed with particular letter combinations. I just have to choose them
and then ftp them to a distant site.
It seems to work for some prefixes, but not others.

I’m doing this:
Dir.glob("{wdp*.pdf,wrr*.pdf,wip*.pdf,wsl*.pdf,wcr*.pdf}").each do
|file|
puts file
ftp the files away . . .
end

So, it’s sending the “wip” file but not the “wsl” file. It doesn’t even
do a simple “puts” for the files that it sees.
I’ve attached my script.
Thanks a lot,
Peter

On Fri, Jul 22, 2011 at 3:22 PM, Peter B. [email protected] wrote:

I’m having a hard time understanding why a simple Dir.glob sequence
isn’t working. I need to interrogate a directory for files that are
prefixed with particular letter combinations.
It seems to work for some prefixes, but not others.

$ mkdir /tmp/z
$ cd /tmp/z
$ touch wdp{1,2,3,4,5,6,7}.pdf
$ touch wrr{1,2,3,4,5,6,7}.pdf
$ touch wip{1,2,3,4,5,6,7}.pdf
$ touch wsl{1,2,3,4,5,6,7}.pdf
$ touch wcr{1,2,3,4,5,6,7}.pdf
$ ruby -v -rpp -e ‘pp
Dir.glob(“{wdp*.pdf,wrr*.pdf,wip*.pdf,wsl*.pdf,wcr*.pdf}”).sort’
ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
[“wcr1.pdf”, “wcr2.pdf”, “wcr3.pdf”, “wcr4.pdf”, “wcr5.pdf”,
“wcr6.pdf”, “wcr7.pdf”,
“wdp1.pdf”, “wdp2.pdf”, “wdp3.pdf”, “wdp4.pdf”, “wdp5.pdf”,
“wdp6.pdf”, “wdp7.pdf”,
“wip1.pdf”, “wip2.pdf”, “wip3.pdf”, “wip4.pdf”, “wip5.pdf”,
“wip6.pdf”, “wip7.pdf”,
“wrr1.pdf”, “wrr2.pdf”, “wrr3.pdf”, “wrr4.pdf”, “wrr5.pdf”,
“wrr6.pdf”, “wrr7.pdf”,
“wsl1.pdf”, “wsl2.pdf”, “wsl3.pdf”, “wsl4.pdf”, “wsl5.pdf”,
“wsl6.pdf”, “wsl7.pdf”]

Are your actual filenames all lowercase?

On Jul 22, 2011, at 12:22 , Peter B. wrote:

Dir.glob("{wdp*.pdf,wrr*.pdf,wip*.pdf,wsl*.pdf,wcr*.pdf}").each do

This doesn’t address your issue, but I thought I’d point out that you
might rather have:

Dir.glob("{wdp,wrr,wip,wsl,wcr}*.pdf")

or even:

Dir.glob(“w{dp,rr,ip,sl,cr}*.pdf”)

I can’t see anything wrong with your original code tho… so yeah, I’d
prolly guess name casing as well.

Ryan D. wrote in post #1012498:

On Jul 22, 2011, at 12:22 , Peter B. wrote:

Dir.glob("{wdp*.pdf,wrr*.pdf,wip*.pdf,wsl*.pdf,wcr*.pdf}").each do

This doesn’t address your issue, but I thought I’d point out that you
might rather have:

Dir.glob("{wdp,wrr,wip,wsl,wcr}*.pdf")

or even:

Dir.glob(“w{dp,rr,ip,sl,cr}*.pdf”)

I can’t see anything wrong with your original code tho… so yeah, I’d
prolly guess name casing as well.

Thanks. Well, that’s a good point. Although, all of the incoming names
so far have been lower-case. I didn’t realize that Dir.glob was case
sensitive. Is there a way to flag it to be case insensitive?
Peter

hm the doc says that File::FNM_CASEFOLD is ignored but on my system it
work:

Dir.glob(“w{dp,rr,ip,sl,cr}*.pdf”,File::FNM_CASEFOLD)