Class | RecursiveUtils::FullPathList |
In: |
recursiveutils.rb
|
Parent: | Object |
pathlist | [R] | new に path を与えた際に作成されるファイルリストの配列. |
path を元にオプション opts に対応するリストを配列で返す.
# File recursiveutils.rb, line 193 def self.get(opts = {}, *path) self.new(opts, path).pathlist end
path を元にディレクトリのリストを配列で返す.
# File recursiveutils.rb, line 244 def get_dir(*path) flag_filter(get_exist(path), 'd') end
path を元に存在するファイルのリストを配列で返す.
# File recursiveutils.rb, line 205 def get_exist(*path) path = path.flatten return path if path.empty? list = Hash.new if @prune lf = LocaleFilter.new('euc', nil, @file_code) pattern = regexp(@prune) end path.each do |i| unless test(?e, i) warn "#{i}: No such file or directory." if @warning next end fullpath = File.expand_path(i) next if @prune && match?(lf.tolocale(fullpath), pattern, fullpath) list[fullpath] = true Find.find(fullpath) do |j| Find.prune if @prune && match?(lf.tolocale(j), pattern, j) list[j] = true end if @recursive && test(?d, fullpath) end list.keys.sort end
path を元に通常ファイルのリストを配列で返す.
# File recursiveutils.rb, line 239 def get_file(*path) flag_filter(get_exist(path), 'f') end
path を元にオプションに対応するリストを配列で返す.
# File recursiveutils.rb, line 234 def get_list(*path) flag_filter(get_exist(path)) end
path を元にシンボリックリンクのリストを配列で返す.
# File recursiveutils.rb, line 249 def get_symlink(*path) flag_filter(get_exist(path), 's') end
配列 list をオプションでフィルタリングして返す.
# File recursiveutils.rb, line 273 def flag_filter(list, type = @file_type) return list if list.empty? l = list m = { :n => 'Not ', :f => 'Regular File', :d => 'Directory', :l => 'Symbolic Link', :o => 'Owner', :g => 'Group Owner', :p => ' permission denied', :r => 'Read', :w => 'Write', :x => 'Execute', :t => 'match of target' } case type.to_s[0, 1].downcase when 'f' separate(l, m[:n] + m[:f]){ |i| test(?f, i) } when 'd' separate(l, m[:n] + m[:d]){ |i| test(?d, i) } when 's' separate(l, m[:n] + m[:l]){ |i| test(?l, i) } else separate(l, m[:f]){ |i| ! test(?f, i) } if @regular separate(l, m[:d]){ |i| ! test(?d, i) } if @directory separate(l, m[:l]){ |i| ! test(?l, i) } if @symlink end separate(l, m[:n] + m[:o]){ |i| test(?o, i) } if @owner separate(l, m[:n] + m[:g]){ |i| test(?G, i) } if @group separate(l, m[:r] + m[:p]){ |i| test(?r, i) } if @readable separate(l, m[:w] + m[:p]){ |i| test(?w, i) } if @writable separate(l, m[:x] + m[:p]){ |i| test(?x, i) } if @executable if @target t = regexp(@target) f = LocaleFilter.new('euc', nil, @file_code) separate(l, m[:n] + m[:t]){ |i| f.tolocale(i) =~ t } end return l end
path が pattern にマッチしたら true を返す.
# File recursiveutils.rb, line 263 def match?(path, pattern, name) if path =~ pattern warn "#{name}: Match remove target." if @warning return true else return false end end
str を元にオプションに対応する正規表現オブジェクトを作成して返す.
# File recursiveutils.rb, line 256 def regexp(str) str = LocaleFilter.convert_str(str, 'euc', @input_code) opt = Regexp::IGNORECASE if @casefold Regexp.new(str, opt, 'e') end