あーるPG - 社会人のデジタル生活

日曜プログラマになろうかなーと思った30代理系社会人の、キャリアアップや趣味(特にデジタル情報)の記録。らーめんとビールが好き。

ディレクトリアクセス

# "." ".."も返る. サブディレクトリでも "hoge.txt"が返る.
Dir.foreach("./") { |file|
    p file
}
# Dir.foreachと同じ
Dir.entries("./").each{ |file|
    p file
}
# 一致するファイルに対して処理を行う.
# **で再帰的に. (hoge/hoge.txtが返る)
Dir.glob("**/*").each { |file|
    print "  [%s]\n" % file
    print "    %s : %s\n" % ["ftype", File::stat(file).ftype.to_s]
    print "    %s : %s\n" % ["mode", File::stat(file).mode.to_s]
    print "    %s : %s\n" % ["size", File::stat(file).size.to_s]
    print "    %s : %s\n" % ["mtime", File::stat(file).mtime.to_s]
    print "    %s : %s\n" % ["directory", File::stat(file).directory?.to_s]
    print "    %s : %s\n" % ["executable", File::stat(file).executable?.to_s]
}