Dir.glob and File.fnmatch

T

Thomas Leitner

Hi,

I always thought that the arguments to Dir.glob(...) and
File.fnmatch(...) are the same. However, with the first I can use
braces, with File.fnmatch not!

irb(main):001:0> Dir['*']
=> ["src", "plugin"]
irb(main):002:0> Dir.glob('s{rc}')
=> ["src"]
irb(main):003:0> File.fnmatch('s{rc}','src')
=> false

Is it somehow possible to use braces with File.fnmatch(...)?

Thomas
 
N

nobu.nokada

Hi,

At Sun, 8 May 2005 23:46:18 +0900,
Thomas Leitner wrote in [ruby-talk:141672]:
I always thought that the arguments to Dir.glob(...) and
File.fnmatch(...) are the same. However, with the first I can use
braces, with File.fnmatch not!

Brace Expansion is different from Pathname Expansion.
 
P

Piergiuliano Bossi

Hi,

At Sun, 8 May 2005 23:46:18 +0900,
Thomas Leitner wrote in [ruby-talk:141672]:
I always thought that the arguments to Dir.glob(...) and
File.fnmatch(...) are the same. However, with the first I can use
braces, with File.fnmatch not!


Brace Expansion is different from Pathname Expansion.

Yes, PickaxeII contains a better explanation than ri and effectively
differentiate the semantics between the two: "Because fnmatch is
implemented by the underlying operating system, it may have different
semantics to Dir.glob." ==> ie: braces are not used to delimit patterns
to match.

IMHO ri description needs to be slightly enhanced.

HTH
Giuliano
 
T

Thomas Leitner

Thanks for the answers! So I will stick to Dir.glob for the time being.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top