D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Dir
/
Filename :
glob-c.ri
back
Copy
U:RDoc::AnyMethod[iI" glob:ETI"Dir::glob;TT:publico:RDoc::Markup::Document:@parts[0o:RDoc::Markup::Paragraph; [I"OForms an array _entry_names_ of the entry names selected by the arguments.;To:RDoc::Markup::BlankLine o; ; [I"MArgument +patterns+ is a string pattern or an array of string patterns; ;TI"0note that these are not regexps; see below.;T@o; ; [I"&Notes for the following examples:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"=<tt>'*'</tt> is the pattern that matches any entry name ;TI"/except those that begin with <tt>'.'</tt>.;To;;0; [o; ; [I"9We use method Array#take to shorten returned arrays ;TI"(that otherwise would be very large.;T@o; ; [I"1With no block, returns array _entry_names_; ;TI"Mexample (using the {simple file tree}[rdoc-ref:Dir@About+the+Examples]):;T@o:RDoc::Markup::Verbatim; [I"7Dir.glob('*') # => ["config.h", "lib", "main.rb"] ;T:@format0o; ; [I"BWith a block, calls the block with each of the _entry_names_ ;TI"and returns +nil+:;T@o;; [I"<Dir.glob('*') {|entry_name| puts entry_name } # => nil ;T;0o; ; [I"Output:;T@o;; [I"config.h ;TI" lib ;TI" main.rb ;T;0o; ; [I"4If optional keyword argument +flags+ is given, ;TI"0the value modifies the matching; see below.;T@o; ; [ I"3If optional keyword argument +base+ is given, ;TI"-its value specifies the base directory. ;TI"KEach pattern string specifies entries relative to the base directory; ;TI""the default is <tt>'.'</tt>. ;TI"JThe base directory is not prepended to the entry names in the result:;T@o;; [ I",Dir.glob(pattern, base: 'lib').take(5) ;TI"^# => ["abbrev.gemspec", "abbrev.rb", "base64.gemspec", "base64.rb", "benchmark.gemspec"] ;TI"0Dir.glob(pattern, base: 'lib/irb').take(5) ;TI"Q# => ["cmd", "color.rb", "color_printer.rb", "completion.rb", "context.rb"] ;T;0o; ; [ I"FIf optional keyword +sort+ is given, its value specifies whether ;TI"7the array is to be sorted; the default is +true+. ;TI">Passing value +false+ with that keyword disables sorting ;TI"K(though the underlying file system may already have sorted the array).;T@o; ; [I"<b>Patterns</b>;T@o; ; [I"%Each pattern string is expanded ;TI"*according to certain metacharacters; ;TI"Nexamples below use the {Ruby file tree}[rdoc-ref:Dir@About+the+Examples]:;T@o;; ;;[o;;0; [ o; ; [I";<tt>'*'</tt>: Matches any substring in an entry name, ;TI"3similar in meaning to regexp <tt>/.*/mx</tt>; ;TI">may be restricted by other values in the pattern strings:;T@o;; ;;[ o;;0; [o; ; [I"*<tt>'*'</tt> matches all entry names:;T@o;; [I"HDir.glob('*').take(3) # => ["BSDL", "CONTRIBUTING.md", "COPYING"] ;T;0o;;0; [o; ; [I"C<tt>'c*'</tt> matches entry names beginning with <tt>'c'</tt>:;T@o;; [I"NDir.glob('c*').take(3) # => ["CONTRIBUTING.md", "COPYING", "COPYING.ja"] ;T;0o;;0; [o; ; [I"@<tt>'*c'</tt> matches entry names ending with <tt>'c'</tt>:;T@o;; [I"EDir.glob('*c').take(3) # => ["addr2line.c", "array.c", "ast.c"] ;T;0o;;0; [o; ; [I"E<tt>'\*c\*'</tt> matches entry names that contain <tt>'c'</tt>, ;TI""even at the beginning or end:;T@o;; [I"ODir.glob('*c*').take(3) # => ["CONTRIBUTING.md", "COPYING", "COPYING.ja"] ;T;0o; ; [I"@Does not match Unix-like hidden entry names ("dot files"). ;TI"2To include those in the matched entry names, ;TI"Cuse flag IO::FNM_DOTMATCH or something like <tt>'{*,.*}'</tt>.;T@o;;0; [ o; ; [I"4<tt>'**'</tt>: Matches entry names recursively ;TI"6if followed by the slash character <tt>'/'</tt>:;T@o;; [I"PDir.glob('**/').take(3) # => ["basictest/", "benchmark/", "benchmark/gc/"] ;T;0o; ; [I"5If the string pattern contains other characters ;TI".or is not followed by a slash character, ;TI"&it is equivalent to <tt>'*'</tt>.;T@o;;0; [o; ; [I"0<tt>'?'</tt> Matches any single character; ;TI"/similar in meaning to regexp <tt>/./</tt>:;T@o;; [I"$Dir.glob('io.?') # => ["io.c"] ;T;0o;;0; [o; ; [I"H<tt>'[_set_]'</tt>: Matches any one character in the string _set_; ;TI"Qbehaves like a {Regexp character class}[rdoc-ref:Regexp@Character+Classes], ;TI"0including set negation (<tt>'[^a-z]'</tt>):;T@o;; [I"&Dir.glob('*.[a-z][a-z]').take(3) ;TI"<# => ["CONTRIBUTING.md", "COPYING.ja", "KNOWNBUGS.rb"] ;T;0o;;0; [ o; ; [I"<tt>'{_abc_,_xyz_}'</tt>: ;TI"2Matches either string _abc_ or string _xyz_; ;TI"Dbehaves like {Regexp alternation}[rdoc-ref:Regexp@Alternation]:;T@o;; [I"5Dir.glob('{LEGAL,BSDL}') # => ["LEGAL", "BSDL"] ;T;0o; ; [I"-More than two alternatives may be given.;T@o;;0; [ o; ; [I"6<tt>\\</tt>: Escapes the following metacharacter.;T@o; ; [I"CNote that on Windows, the backslash character may not be used ;TI"in a string pattern: ;TI"Q<tt>Dir['c:\\foo*']</tt> will not work, use <tt>Dir['c:/foo*']</tt> instead.;T@o; ; [I"SMore examples (using the {simple file tree}[rdoc-ref:Dir@About+the+Examples]):;T@o;; [I"'# We're in the example directory. ;TI"+File.basename(Dir.pwd) # => "example" ;TI"9Dir.glob('config.?') # => ["config.h"] ;TI"8Dir.glob('*.[a-z][a-z]') # => ["main.rb"] ;TI"9Dir.glob('*.[^r]*') # => ["config.h"] ;TI"DDir.glob('*.{rb,h}') # => ["main.rb", "config.h"] ;TI"KDir.glob('*') # => ["config.h", "lib", "main.rb"] ;TI"PDir.glob('*', File::FNM_DOTMATCH) # => [".", "config.h", "lib", "main.rb"] ;TI"DDir.glob(["*.rb", "*.h"]) # => ["main.rb", "config.h"] ;TI" ;TI"Dir.glob('**/*.rb') ;TI":=> ["lib/song/karaoke.rb", "lib/song.rb", "main.rb"] ;TI" ;TI"MDir.glob('**/*.rb', base: 'lib') # => ["song/karaoke.rb", "song.rb"] ;TI" ;TI"4Dir.glob('**/lib') # => ["lib"] ;TI" ;TI"SDir.glob('**/lib/**/*.rb') # => ["lib/song/karaoke.rb", "lib/song.rb"] ;TI" ;TI"<Dir.glob('**/lib/*.rb') # => ["lib/song.rb"] ;T;0o; ; [I"<b>Flags</b>;T@o; ; [I"VIf optional keyword argument +flags+ is given (the default is zero -- no flags), ;TI"Hits value should be the bitwise OR of one or more of the constants ;TI"'defined in module File::Constants.;T@o; ; [I" Example:;T@o;; [I"4flags = File::FNM_EXTGLOB | File::FNM_DOTMATCH ;T;0o; ; [I"MSpecifying flags can extend, restrict, or otherwise modify the matching.;T@o; ; [I"QThe flags for this method (other constants in File::Constants do not apply):;T@o;; ;;[ o;;0; [o; ; [I"File::FNM_DOTMATCH: ;TI"<specifies that entry names beginning with <tt>'.'</tt> ;TI"'should be considered for matching:;T@o;; [ I"Dir.glob('*').take(5) ;TI"F# => ["BSDL", "CONTRIBUTING.md", "COPYING", "COPYING.ja", "GPL"] ;TI"6Dir.glob('*', flags: File::FNM_DOTMATCH).take(5) ;TI"O# => [".", ".appveyor.yml", ".cirrus.yml", ".dir-locals.el", ".document"] ;T;0o;;0; [o; ; [I"File::FNM_EXTGLOB: ;TI"#enables the pattern extension ;TI"F<tt>'{_a_,_b_}'</tt>, which matches pattern _a_ and pattern _b_; ;TI"behaves like a ;TI"+{regexp union}[rdoc-ref:Regexp.union] ;TI"$(e.g., <tt>'(?:_a_|_b_)'</tt>):;T@o;; [I"pattern = '{LEGAL,BSDL}' ;TI"3Dir.glob(pattern) # => ["LEGAL", "BSDL"] ;T;0o;;0; [o; ; [I"File::FNM_NOESCAPE: ;TI"Gspecifies that escaping with the backslash character <tt>'\'</tt> ;TI";is disabled; the character is not an escape character.;T@o;;0; [o; ; [I"File::FNM_PATHNAME: ;TI"Aspecifies that metacharacters <tt>'*'</tt> and <tt>'?'</tt> ;TI"'do not match directory separators.;T@o;;0; [o; ; [I"File::FNM_SHORTNAME: ;TI"Ospecifies that patterns may match short names if they exist; Windows only.;T: @fileI"dir.rb;T:0@omit_headings_from_table_of_contents_below0I"�Dir.glob(*patterns, flags: 0, base: nil, sort: true) -> array Dir.glob(*patterns, flags: 0, base: nil, sort: true) {|entry_name| ... } -> nil ;T0[ I"@(pattern, _flags = 0, flags: _flags, base: nil, sort: true);T@FI"Dir;TcRDoc::NormalClass00