Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by kinz Oct 06, 2009
- 2487 views
Hi kinz,
When opening the console, default code page is 850. According to this page sent to me earlier, 865 (Nordic) is probably the one I should change to before running the DIR command...
Your default code page 850 seems to be namely OEM (DOS) code page, but cp865 seems to be some code page with win-1252 encoding for "æøåÆØÅ" letters.
The DIR command uses strongly OEM encoding.
This is what I did;
- Created folder "æøåÆØÅ" under "c:\data\test".
- Opened console (cmd)
- Changed to "c:\data\test"
- Confirmed current code page 850 (using chcp w/o params.)
- chcp 865
Try the chcp w/o params to see if cp was changed to 865 really.
- dir *.* /b > files.txt
- Opened "files.txt" using notepad.
- Changed to font to "Terminal".
OK, Terminal has strongly OEM encoding.
Letters "æøåÆØÅ" are now visible.
So, DIR worked in OEM (850).
I use Font "Lucida Console" / Script "Western" as a default (did a little research, and this is the default font/script setting for everybody..), and æøåÆØÅ is perfectly usable characters in this font. But, when æøåÆØÅ is routed through DIR's redirection, it becomes garbled. Apperantly, they have a different byte representation in Western script compared to OEM/DOS? If so, it seems I have to go through the file replacing it with the correct byte representation for "Lucidia Concole / Western", (which shouldn't really be a problem..)?
"Lucida Console" has Windows encoding 1251 here, in Russia, so yours one works same way, on cp1252, and can not display OEM text properly, I think.
I use recoding to write and read Russian file names in EU.
The ed editor works as OEM thing, so recodind is not needed, but if I program in, say, Notepad or Edita or such a Windows editor, I need recode from 1251 to 866 the file names and Russian output of DIR, if I want to read output in Notepad or Edita without changeing the font to Terminal.
That said, I would have used Euphoria - and not Console/DIR, but I've got no idea how I can produce the information I'm after (with the exception of path/filename, ofcourse);
- Created date/time
- Created by
- Filename/path
Try the function below, it is not tested, but gives the idea, I hope.
constant W = {#E6,#F8,#E5,#C6,#D8,#C5}, -- codes of your letters in 1252 O = {#91,#9B,#86,#92,#9D,#8F}, -- codes of same letters in 850 W_to_O = 1, -- mode from Windows to OEM O_to_W = 2 -- mode from OEM to Windows function recode_nor(sequence input, -- input text (command or DIR output) integer mode) -- W_to_O, or O_to_W integer c, d for i=1 to length(input) do c = input[i] if mode = W_to_O then d = find(c, W) if d then input[i]= O[d] end if end if if mode = O_to_W then d = find(c, O) if d then input[i]= W[d] end if end if end for return input end function
Regards,
kinz