カテゴリー
Rubyスクリプト

filefind3.rb

require 'fileutils'
# ファイルの情報を表示 netから拾いました。
def stat(path)
s = File::Stat.new(path)
begin
puts " : #{s.birthtime} (ファイル作成日時)"
rescue NotImplementedError => e
puts e.inspect
end
puts " : #{s.mtime} (最終更新日時 modify time)"
puts " : #{s.ctime} (最終状態変更日時 change time)"
puts " : #{s.atime} (最終アクセス日時 access time)"
end

def getallfiles(filename,desc)
print filename,"を探します。","\n"
Dir.glob('**/*') do |item|
ary = item.split("/")

if ary[1] == nil
#.txtがprintされるのを防ぐ
if !ary[0].include?(".")
print ary[0],"\n"
end
elsif File.fnmatch?(filename,ary[1])
print " /"
printf("%-20s\n", ary[1])
stat(item)if desc == true #--descの指定があるとき
end
end
end

begin
if ARGV[0]==nil
print ("[USEAGE]findfile [--name] name [--desc]")
exit(1)
end
op = ARGV
desc = op[2] == "--desc" ? true : false
if op[0] == "--name"
filename = op[1]
#ファイル名で検索します。正規表現も使える
getallfiles(filename,desc)
else
print("--name filename.ext --descと指定します。")
#上以外は無しです
1 / 0
end

rescue
print("エラーが起きました。")
exit(1)
else
print("処理を終わります。")
end
カテゴリー
Rubyスクリプト

Ruby-list Tutorial 200~

p Math.sqrt(2) #=>1.4142135623730951
p Math::PI #=>3.141592653589793

=begin
trap "SIGURS1", 'print "foobar"'
kill "SIGURS1", $$
=end

proc = proc{print "foo\n"}
proc.call #=>foo

p self #=>main

proc2 = proc{print "$x changed ";
print "$x = ",$x,"\n"
}
trace_var (:$x){
proc2.call #=>$x changed $x = 5
}
$x = 5
inserted by FC2 system