{"id":8922,"date":"2022-09-15T23:24:55","date_gmt":"2022-09-15T21:24:55","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=8922"},"modified":"2024-07-23T23:07:49","modified_gmt":"2024-07-23T21:07:49","slug":"windows-determine-textencoding-of-a-file","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/windows-determine-textencoding-of-a-file\/","title":{"rendered":"Windows: Determine Textencoding of a File"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_8922 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_8922')){$('.twoclick_social_bookmarks_post_8922').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Windows%3A%20Determine%20Textencoding%20of%20a%20File\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Aif%20you%20are%20working%20with%20special%20characters%20%28i.e.%20German%20Umlaute%29%20within%20a%20Textfile%20it%20is%20importent%20to%20know%20with%20which%20text%20encoding%20%28UTF8%2C%20ASCII...%29%20a%20file%20is%20saved.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/windows-determine-textencoding-of-a-file\\\/\",\"post_id\":8922,\"post_title_referrer_track\":\"Windows%3A+Determine+Textencoding+of+a+File\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>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&#8230;) a file is saved.<br \/>\n<!--more--><\/p>\n<p>This cannot be be determine when a file is opened in Textmode because each file is converted (.NET) to UTF16 encoding into memory.<\/p>\n<p>The solution is to open the file as stream, and read it. Here a powershell solution:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; $oFileStream=New-Object System.IO.StreamReader(&quot;D:\\myTextFile.ps1&quot;,$true)\r\nPS D:\\&gt; $oFileStream.Read()\r\nPS D:\\&gt; $oFileStream.CurrentEncoding\r\nBodyName          : utf-8\r\nEncodingName      : Unicode (UTF-8)\r\nHeaderName        : utf-8\r\nWebName           : utf-8\r\nWindowsCodePage   : 1200\r\nIsBrowserDisplay  : True\r\nIsBrowserSave     : True\r\nIsMailNewsDisplay : True\r\nIsMailNewsSave    : True\r\nIsSingleByte      : False\r\nEncoderFallback   : System.Text.EncoderReplacementFallback\r\nDecoderFallback   : System.Text.DecoderReplacementFallback\r\nIsReadOnly        : True\r\nCodePage          : 65001\r\nPS D:\\&gt; $oFileStream.Close()\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;) a file is saved.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,5],"tags":[1889,853,1888,1887,1026,20],"class_list":["post-8922","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-windowsknowhow","tag-asci","tag-determine","tag-encoding","tag-testfile","tag-utf8","tag-windows-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/8922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=8922"}],"version-history":[{"count":2,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/8922\/revisions"}],"predecessor-version":[{"id":8924,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/8922\/revisions\/8924"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=8922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=8922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=8922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}