[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Dir.glob and File.fnmatch

Thomas Leitner

5/8/2005 2:46:00 PM

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

--
|\ Thomas Leitner -- thomas [underscore] leitner [at] gmx [dot] at
|>
|/ "Life is what happens to you while you're busy making other plans"



3 Answers

nobu.nokada

5/9/2005 11:26:00 PM

0

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.

--
Nobu Nakada


Piergiuliano Bossi

5/10/2005 9:21:00 AM

0

nobu.nokada@softhome.net wrote:
> 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

--
If you want to send me an email address should be 'p', then a dot,
followed by 'bossi' at 'quinary', another dot and 'com' at last

Thomas Leitner

5/11/2005 9:18:00 AM

0

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

Thomas