指定したディレクトリにあるファイル名を変更する
ネタがなかったら、2週間も空いてしまった。しかたないのでRubyネタ。よく忘れるからメモしておく。
指定したディレクトリの拡張しを .htm → .html に変更するプログラム。
dir = Dir.new(gets.to_s.chomp) dir.each do |file_name| s = file_name.to_s next if s !~ /\.htm$/ infile = File.new(s, "r") outfile = File.new(s.gsub(/\.htm/, ".html"), "w") while line = infile.gets outfile.puts line end outfile.close infile.close File.delete(s) end