2006/06/28
文字コードの変換II
元記事はhttp://winscript.s41.xrea.com/mt/archives/2005/09/post_3.htmlです。
文字コードを変換するサンプルスクリプトです。例では引数に与えたShift_JISのテキストファイルをUTF-8に変換します。.NET Frameworkのオブジェクトを自由自在に呼び出せる便利さを味わってください。
$sr = new-object System.IO.StreamReader ( $args[0], [System.Text.Encoding]::GetEncoding("sjis")) $sw = new-object System.IO.StreamWriter ( ([System.IO.Path]::GetFileNameWithoutExtension($args[0]) + "_utf8" + [System.IO.Path]::GetExtension($args[0])), [System.Text.Encoding]::GetEncoding("utf-8")) while (($line = $sr.ReadLine()) -ne $null){ $sw.WriteLine($line) } $sr.Close() $sw.Close()元記事:http://blogs.wankuma.com/mutaguchi/archive/2006/06/28/31470.aspx
プライバシーポリシー