Perl/linuxで複数ファイルの文字コード変換
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[Perl]]
+Shift-JISなどのtxtファイルをUTF-8へ変換するスクリプト
@ls = `ls *.txt`;
chomp @ls;
foreach$file(@ls){
$file_utf8 = $file;
$file_utf8 =~ s/\.(.*)?$//;
$file_utf8.= ".utf8";
system("nkf -w $file > tmp");
system("mv tmp $file_utf8");
print "nkf -w $file > tmp\n";
}
+ディレクトリ構造になっている場合、Shift-JISなどのtxtファイルをUTF-8へ変換するスクリプト
--use File::Findを利用した再帰的な方法
use File::Find;
@ARGV = qw(.) unless @ARGV;
find sub { push @list, $File::Find::name, -d && '/', "\n"}, @ARGV;
chomp @list;
foreach(@list){
unless($_){next;}
if(/^\//){next;}
print "nkf -w $_ > tmp\n";
system("nkf -w $_ > tmp");
system("mv tmp $_");
}
終了行:
[[Perl]]
+Shift-JISなどのtxtファイルをUTF-8へ変換するスクリプト
@ls = `ls *.txt`;
chomp @ls;
foreach$file(@ls){
$file_utf8 = $file;
$file_utf8 =~ s/\.(.*)?$//;
$file_utf8.= ".utf8";
system("nkf -w $file > tmp");
system("mv tmp $file_utf8");
print "nkf -w $file > tmp\n";
}
+ディレクトリ構造になっている場合、Shift-JISなどのtxtファイルをUTF-8へ変換するスクリプト
--use File::Findを利用した再帰的な方法
use File::Find;
@ARGV = qw(.) unless @ARGV;
find sub { push @list, $File::Find::name, -d && '/', "\n"}, @ARGV;
chomp @list;
foreach(@list){
unless($_){next;}
if(/^\//){next;}
print "nkf -w $_ > tmp\n";
system("nkf -w $_ > tmp");
system("mv tmp $_");
}
ページ名: