ZTree.com  | ZEN  | About...  

 Index   Back

[Discuss] INI file management from command line?   [Discuss]

By: Art Kocsis     So Calif  
Date: Sep 11,2017 at 01:11
In Response to: [Discuss] INI file management from command line? (Slobodan Vujnovic)

Au Contraire! Then the obvious thing is to simply convert the Unicode text to ANSI.

Unix/Linux has a little command line tool, IConv, that does just that. Actually, it will convert a multitude of char encoding from one to another and has been ported to Windows. Google iconv+windows

See: https://dbaportal.eu/2012/10/24/iconv-for-windows/ for instructions

However, this semi-port is a bit of overkill for simply converting Unicode to ANSI as the installation yields 11 files using over 1MB of disk space. There is supposed to be a true windows port of IConv called Win-IConv but finding a binary proved to be difficult although the source is readily available at github. Another purported "portable" solution, GetText, turned out to be a huge tree taking up almost 100 MB of space! (In fairness, though, it is an entire multi-language translation package.)

This has now become a challenge. How difficult can it be to write a program to copy a file and discard every other byte? It must be a common task so why aren't there lots of utils available to do it? In frustration I did what I should have done in the first place: Google convert+"UNicode to ANSI"

Finally! Turns out to be much simpler than I thought: The tried and true legacy DOS TYPE command found on all (32 bit only?), windows machines converts to and from ASCII to Unicode! Simply TYPE the file and redirect stdout to a new file! Duh!!! (The conversion from ANSI to Unicode is slightly more complicated. See Rob VanderWoude's page.)

Type Unicode.txt > ASCII.txt

To include extended ASCII characters, reset the current Code Page to 1252:

CHCP 1252 & Type Unicode.txt > ANSI.txt

Putting it all together with the previous (or just use the last line):

<<<<<<<<<<<<<<<<<<<<<<<<<< Code start >>>>>>>>>>>>>>>>>>>>>>>>>
:: Command file to extract and sort ini file section titles
Set bgn=%date:~-2,2%-%date:~0,2%-%date:~3,2% %time:~0,2%:%time:~3,2%
Set bgn=%bgn: = 0%
Echo Date Time: %bgn% > "%~n1.xtr"
Echo Ini Source: %1 >> "%~n1.xtr"
Echo Ini Sections: >> "%~n1.xtr"
Echo ================ >> "%~n1.xtr"
CHCP 1252 & Type Unicode.txt | Findstr /b /c:[ "%1" | Sort >> "%~n1.xtr" 2>&1
<<<<<<<<<<<<<<<<<<<<<<<<<< Code End >>>>>>>>>>>>>>>>>>>>>>>>>

If TYPE is not available, StringConverter is an alternate freeware console tool that is still available via the Wayback Machine. I haven't tried it but it was recommended on a forum (link below).

So in spite of all the upturned noses of the GUI only users, those who need or want to work efficiently make good and extensive use of command line resources (and If they are really smart, they are also ZTree users!)

Refs (Freeware unless otherwise noted):
Convert Unicode files to ANSI (StringConverter, V - The File Viewer, Type)
The TYPE command
StringConverter (command line convert a FILE or a string from/to ANSI, OEM, BASE64, UNICODE)
Universal Viewer (freeware version available, has been mentioned here many times, GUI only?)
V - The File Viewer (Extensive command line support, $20 but looks very impressive, also other utils)
ICONV for Windows (Unix util, DL links & installation instructions, 11 files/1 MB, incls GetText.exe)
Win-IConv (source code only)
GetText and IConv Binaries for Windows (full translations for 37 locales, 98 MB instl)
A Quick Gettext Tutorial

Sheeesh. this was supposed to be just a simple answer!


Namaste', Art

Press any key to exit,
Press any other key to continue...
- unknown

Thread locked

Messages in this Thread

95,045 Postings in 11,981 Threads, 349 registered users, 84 users online (1 registered, 83 guests)
Index | Admin contact |   Forum Time: Jul 11, 2020 - 9:17 am EDT  |  Hits:32,106,965  (10,588 Today )
RSS Feed