ちんとんがめ♪色々備忘録・・・

なんか、メモ的な感じで使えればいいなみたいな。。。前検索したけど、忘れて同じもの検索するのって面倒だよね?・・・でも、結局検索するみたいな。。。

PowerShellでそれぞれのEncodingオプションを実行してみた。

んで、nkfツール使って、ファイルの文字コードが何になっているか実行してみた。
う~ん・・・そうなんだ?
どこの環境でも同じなのかな・・・?

例)テスト.ps1
$test = (Get-Content C:\テスト\テスト.txt)
$test2 = (Get-Content C:\テスト\テスト.txt -Encoding Byte)
$test3 = (Get-Content C:\テスト\テスト2.txt)
$test4 = (Get-Content C:\テスト\テスト2.txt -Encoding Byte)
$test | Set-Content C:\テスト\テスト_Ascii.txt -Encoding Ascii
$test | Set-Content C:\テスト\テスト_BigEndianUnicode.txt -Encoding BigEndianUnicode
$test2 | Set-Content C:\テスト\テスト_Byte.txt -Encoding Byte
$test4 | Set-Content C:\テスト\テスト_Byte2.txt -Encoding Byte
$test | Set-Content C:\テスト\テスト_Default.txt -Encoding Default
$test3 | Set-Content C:\テスト\テスト_Default2.txt -Encoding Default
$test | Set-Content C:\テスト\テスト_Oem.txt -Encoding Oem
$test3 | Set-Content C:\テスト\テスト_Oem2.txt -Encoding Oem
$test | Set-Content C:\テスト\テスト_String.txt -Encoding String
$test3 | Set-Content C:\テスト\テスト_String2.txt -Encoding String
$test | Set-Content C:\テスト\テスト_Unicode.txt -Encoding Unicode
$test | Set-Content C:\テスト\テスト_Unknown.txt -Encoding Unknown
$test | Set-Content C:\テスト\テスト_UTF32.txt -Encoding UTF32
$test | Set-Content C:\テスト\テスト_UTF7.txt -Encoding UTF7
$test | Set-Content C:\テスト\テスト_UTF8.txt -Encoding UTF8

Write-Host "C:\テスト\テスト_Ascii.txt : " (.\nkf.exe -g C:\テスト\テスト_Ascii.txt)
Write-Host "C:\テスト\テスト_BigEndianUnicode.txt : " (.\nkf.exe -g C:\テスト\テスト_BigEndianUnicode.txt)
Write-Host "C:\テスト\テスト_Byte.txt : " (.\nkf.exe -g C:\テスト\テスト_Byte.txt)
Write-Host "C:\テスト\テスト_Byte2.txt : " (.\nkf.exe -g C:\テスト\テスト_Byte2.txt)
Write-Host "C:\テスト\テスト_Default.txt : " (.\nkf.exe -g C:\テスト\テスト_Default.txt)
Write-Host "C:\テスト\テスト_Default2.txt : " (.\nkf.exe -g C:\テスト\テスト_Default2.txt)
Write-Host "C:\テスト\テスト_Oem.txt : " (.\nkf.exe -g C:\テスト\テスト_Oem.txt)
Write-Host "C:\テスト\テスト_Oem2.txt : " (.\nkf.exe -g C:\テスト\テスト_Oem2.txt)
Write-Host "C:\テスト\テスト_String.txt : " (.\nkf.exe -g C:\テスト\テスト_String.txt)
Write-Host "C:\テスト\テスト_String2.txt : " (.\nkf.exe -g C:\テスト\テスト_String2.txt)
Write-Host "C:\テスト\テスト_Unicode.txt : " (.\nkf.exe -g C:\テスト\テスト_Unicode.txt)
Write-Host "C:\テスト\テスト_Unknown.txt : " (.\nkf.exe -g C:\テスト\テスト_Unknown.txt)
Write-Host "C:\テスト\テスト_UTF32.txt : " (.\nkf.exe -g C:\テスト\テスト_UTF32.txt)
Write-Host "C:\テスト\テスト_UTF7.txt : " (.\nkf.exe -g C:\テスト\テスト_UTF7.txt)
Write-Host "C:\テスト\テスト_UTF8.txt : " (.\nkf.exe -g C:\テスト\テスト_UTF8.txt)

【実行結果】
PS C:\テスト> C:\テスト\テスト.ps1
C:\テスト\テスト_Ascii.txt : ASCII
C:\テスト\テスト_BigEndianUnicode.txt : UTF-16
C:\テスト\テスト_Byte.txt : CP932
C:\テスト\テスト_Byte2.txt : Shift_JIS
C:\テスト\テスト_Default.txt : CP932
C:\テスト\テスト_Default2.txt : Shift_JIS
C:\テスト\テスト_Oem.txt : CP932
C:\テスト\テスト_Oem2.txt : Shift_JIS
C:\テスト\テスト_String.txt : CP932
C:\テスト\テスト_String2.txt : Shift_JIS
C:\テスト\テスト_Unicode.txt : UTF-16
C:\テスト\テスト_Unknown.txt : UTF-16
C:\テスト\テスト_UTF32.txt : UTF-32
C:\テスト\テスト_UTF7.txt : ASCII
C:\テスト\テスト_UTF8.txt : UTF-8