方法1〜自力編〜
# dir : サーチするディレクトリ
# depth : 階層の深さ(tabインテンドの表示数)
def my_walk(dir, depth)
Dir.foreach(dir){|name|
if name != '.' and name != '..' then
path = File.join(dir,name)
case File.ftype(path)
when "file"
puts "\t" * depth + path
when "directory"
puts "\t" * depth + path + "/"
my_walk(path, depth+1)
end
end
}
end
my_walk("C:\\usr\\local\\share", 0)
方法2〜ライブラリ編〜
require 'find'
Find.find() do |f|
puts "#{f}"
end
方法3〜正規表現ワイルドカード編〜
Dir.glob("C:/usr/local/share/**/") { |name|
puts name
}