def Dir.multiglob( *patterns )
options = (Hash === patterns.last ? patterns.pop : {})
bitflags = 0
bitflags |= File::FNM_NOESCAPE if options[:noescape]
bitflags |= File::FNM_CASEFOLD if options[:casefold]
bitflags |= File::FNM_PATHNAME if options[:pathname] or options[:strict]
bitflags |= File::FNM_DOTMATCH if options[:dotmatch] or options[:strict]
patterns = [patterns].flatten.compact
patterns_include = patterns.select{ |f| f !~ /^[-]/ }
patterns_exclude = patterns.select{ |f| f =~ /^[-]/ }
patterns_include.collect!{ |f| f =~ /^[+]/ ? f[1..-1] : f }
patterns_exclude.collect!{ |f| f =~ /^[-]/ ? f[1..-1] : f }
if options[:recurse]
patterns_include += patterns_include.collect{ |f| File.join(f, '**', '*') }
patterns_exclude += patterns_exclude.collect{ |f| File.join(f, '**', '*') }
end
files = []
files += patterns_include.collect{ |pattern| Dir.glob(pattern, bitflags) }.flatten.uniq
files -= patterns_exclude.collect{ |pattern| Dir.glob(pattern, bitflags) }.flatten.uniq
return files
end