4
我有一個用於文件字符編碼對話的PowerShell腳本。PowerShellscript,錯誤的文件編碼對話
Get-ChildItem -Path D:/test/data -Recurse -Include *.txt |
ForEach-Object {
$inFileName = $_.DirectoryName + '\' + $_.name
$outFileName = $inFileName + "_utf_8.txt"
Write-Host "windows-1251 to utf-8: " $inFileName -> $outFileName
E:\bin\iconv\iconv.exe -f cp1251 -t utf-8 $inFileName > $outFileName
}
但是,而不是UTF-8它文件的字符編碼轉換爲UTF-16。當我從命令行調用iconv實用程序時,它工作正常。
我該怎麼做?
您確定Get-Content cmdlet與-Encoding有關嗎? –
@ Gustav.Calder - 是的,有 – manojlds
@ Gustav.Calder有,但它沒有出現在'Get-Content'的幫助中,因爲它是由FileSystem提供者提供的一個動態參數。您可以在'Get-Help FileSystem'中找到更多信息。 – ajk