半角カタカナを全角へ変換しちゃう

0

rubyで目的とすることだけ。
!/usr/bin/env ruby
require “find”
require “fileutils”
require “kconv”
require “nkf”
unless ARGV[0]
print “ta-taX0201.rb -Version0.1- 2009/6/25n”
print “t使用方法ntt./ta-taX0201.rb pathnn”
exit 1
end
#---------------------------------------------------------#
# ディレクトリとファイルは別々に処理してます
# 何かいい案ありませんか
#---------------------------------------------------------#
def dirrename(path)
Find.find(File.expand_path(path)){ |file|
if File.directory?(file) then
Find.prune if file =~ /.recycle/
if file =~ /(?:xEFxBD[xA1-xBF]|xEFxBE[x80-x9F])/ then
File.rename(file, NKF::nkf(‘-WwX -m0’, file))
puts file + ” をn” + NKF::nkf(‘-WwX -m0’, file) + ” に変更しました。”
end
end
}
end
def filerename(path)
Find.find(File.expand_path(path)){ |file|
if File.file?(file) then
Find.prune if file =~ /.recycle/
if file =~ /(?:xEFxBD[xA1-xBF]|xEFxBE[x80-x9F])/ then
File.rename(file, NKF::nkf(‘-WwX -m0’, file))
puts file + ” をn” + NKF::nkf(‘-WwX -m0’, file) + ” に変更しました。”
end
end
}
end
dirrename(ARGV[0])
filerename(ARGV[0])
こんな感じで指定した場所以下を再帰的に探し回って、変換して。
使うときは自己責任で。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です