23. Dezember 2014 18:32
Function Convert_OEM850_UTF8
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_UTF8" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_OEM850_UTF8_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName -initialDirectory "$env:HOMEDRIVE\temp"
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_UTF8" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Function Convert_OEM852_UTF8_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName -initialDirectory "$env:HOMEDRIVE\temp"
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(852)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_UTF8" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Function Convert_OEM850_UTF16
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(1200)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_UTF16" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_OEM850_ANSI1252
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(1252)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_ANSI1252" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_OEM850_ISO88591
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(28591)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_ISO8859_1" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_ANSI1252_UTF8
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(1252)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_UTF8" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_ISO88591_UTF8
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(28591)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_UTF8" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_ISO88591_ANSI1252
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(28591)
$targetEncoding = [System.Text.Encoding]::GetEncoding(1252)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_ANSI1252" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_OEM850_EBCDIC500
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(500)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_EBCDIC500" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_UTF8_OEM850
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_OEM850" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_UTF8_OEM852
{
# Code page 852 is for Central-/Eastern European NAV Systems (Poland, Czech Rep. etc. ) without Baltic States
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(852)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_OEM852" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_UTF16_OEM850
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(1200) # Little-Endian, for Big-Endian 1201
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_OEM850" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_ANSI1252__OEM850
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(1252)
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_OEM850" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_UTF8_ANSI1252
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(1252)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_ANSI1252" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
Function Convert_UTF8_ISO88591
{
$args = resolve-path $args
$WorkingFolder = Split-Path -Parent $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(28591)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($args) +"_ISO8859_1" + [System.IO.Path]::GetExtension($args)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $args 'converted to' $convertedFileName
}
29. Januar 2016 14:16
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$convertedfile = New-Item -path ".\$convertedFileName" -type file
$WorkingFolder = Split-Path -Parent $args
5. August 2017 17:05
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
4. Oktober 2017 11:00
Function Convert_OEM850_UTF8_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.Title = "Please select an OEM850 file"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "C:\temp" # This is the default path in OpenFile window. Use whatever you like :-)
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_UTF8" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Function Convert_ShiftJIS_UTF8_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.Title = "Please select a Shift_JIS file"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "C:\temp" # This is the default path in OpenFile window. Use whatever you like :-)
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(932)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_UTF8" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Function Convert_UTF8_UTF16_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.Title = "Please select a UTF-8 file"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "C:\temp" # This is the default path in OpenFile window. Use whatever you like :-)
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(1200)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_UTF16" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Function Convert_UTF16_OEM850_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName -initialDirectory "$env:HOMEDRIVE\temp"
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(1200) # Little-Endian, for Big-Endian 1201
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_OEM850" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
# Normalization required if file contains different unicode encoding methods for special chars
$textfile = $textfile.Normalize([Text.NormalizationForm]::FormC)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Function Convert_ANSI1252_OEM850_Dlg
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "TXT (*.txt)|*.txt|CSV (*.csv)|*.csv|All files|*.*"
$OpenFileDialog.Title = "Please select an OEM850 file"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "C:\temp" # This is the default path in OpenFile window. Use whatever you like :-)
if ($inputfile -eq "") {throw 'Please select a file'}
$WorkingFolder = Split-Path -Parent $inputfile
$sourceEncoding = [System.Text.Encoding]::GetEncoding(1252)
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_OEM850" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file
$textfile = [System.IO.File]::ReadAllText($inputfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
Write-host $inputfile 'converted to' $convertedFileName
}
Convert_ANSI1252_OEM850_Dlg
10. November 2017 11:42
Kowa hat geschrieben: […]kommt es sonst bei letzterem Verfahren zu dem Effekt, dass in der Codepagedatei statt einem Zeichen dann 2 oder 3 Zeichen stehen.
23. August 2019 13:47
Function ConvertAndReplace_OEM850_UTF8
{
$args = resolve-path $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($args, $textfile, $targetencoding)
Write-host "Content in $args converted from OEM850 to UTF-8"
}
Function ConvertAndReplace_ANSI1252_UTF8
{
$args = resolve-path $args
$sourceEncoding = [System.Text.Encoding]::GetEncoding(1252)
$targetEncoding = [System.Text.Encoding]::GetEncoding(65001)
$textfile = [System.IO.File]::ReadAllText($args, $sourceencoding)
[System.IO.File]::WriteAllText($args, $textfile, $targetencoding)
Write-host "Content in $args converted from ANSI1252 to UTF-8"
}