[an error occurred while processing this directive] [an error occurred while processing this directive]

Rubyのファイル操作

パス名以下の全てのファイルについてループ
Find.find("パス名") do |f|
  print f
end
fには"パス名"で指定したところからの相対パスが入ります。 下みたいにディレクトリを開く場合は、fにはファイル名しか入らないので、ちょっと挙動が違います。
Dir.open("パス名").each do |f|
  print f
end
src = "img" dest = "dest" Dir.open(src).each { |f| next unless f =~ /(.+)\.(\w+)/ f_l = File.join(src,f) new_f_l = File.join(dest, $1 + "1E3." + $2) `convert -pointsize 20 -fill blue -draw "text 100,100 'HD'" #{f_l} #{new_f_l}` #File.cp(f_l, new_f_l) #system(s) #new_f_l = File.join(dest, $1 + "1E2" + $2) #system(s) } require

ret = File.join("/tmp", "hello")
ret には /tmp/hello が入る。
updated_files = ["capsule__BITRATE_10E2__.mpg", "capsule__BITRATE_10E3__.mpg", "capsule__BITRATE_10E4__.mpg", "hoge"]
ptn = /.+__BITRATE_\d+E\d+__\.mpg/

updated_files.each { |f|
  if f =~ ptn then
    print "#{f} is matched against ptn\n"
  else
    print "#{f} is not matched against ptn\n"
  end
}
  • ファイルサイズを取得
    File.size("hoge.txt")
    
  • [an error occurred while processing this directive]