Dir.glob and File.fnmatch

Discussion in 'Ruby' started by Thomas Leitner, May 8, 2005.

  1. 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"
    Thomas Leitner, May 8, 2005
    #1
    1. Advertising

  2. Thomas Leitner

    Guest

    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
    , May 10, 2005
    #2
    1. Advertising

  3. 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
    Piergiuliano Bossi, May 10, 2005
    #3
  4. Thanks for the answers! So I will stick to Dir.glob for the time being.

    Thomas
    Thomas Leitner, May 11, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georgy Pruss
    Replies:
    15
    Views:
    716
    Tim Roberts
    Dec 1, 2003
  2. Tim Peters
    Replies:
    1
    Views:
    350
    Duncan Booth
    Dec 1, 2003
  3. abcd
    Replies:
    4
    Views:
    451
    Gabriel Genellina
    Jan 8, 2007
  4. Matthew Denner
    Replies:
    1
    Views:
    167
  5. qanda
    Replies:
    1
    Views:
    107
    Tassilo v. Parseval
    Sep 15, 2003
Loading...

Share This Page