Hi,
if you are working with special characters (i.e. German Umlaute) within a Textfile it is importent to know with which text encoding (UTF8, ASCII…) a file is saved.
This cannot be be determine when a file is opened in Textmode because each file is converted (.NET) to UTF16 encoding into memory.
The solution is to open the file as stream, and read it. Here a powershell solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | PS D:\> $oFileStream=New-Object System.IO.StreamReader("D:\myTextFile.ps1",$true)PS D:\> $oFileStream.Read()PS D:\> $oFileStream.CurrentEncodingBodyName : utf-8EncodingName : Unicode (UTF-8)HeaderName : utf-8WebName : utf-8WindowsCodePage : 1200IsBrowserDisplay : TrueIsBrowserSave : TrueIsMailNewsDisplay : TrueIsMailNewsSave : TrueIsSingleByte : FalseEncoderFallback : System.Text.EncoderReplacementFallbackDecoderFallback : System.Text.DecoderReplacementFallbackIsReadOnly : TrueCodePage : 65001PS D:\> $oFileStream.Close() |
Michael