DOS TREE line drawing characters: How to print?
Moderator: DosItHelp
-
- Posts: 47
- Joined: 01 Jul 2011 13:37
DOS TREE line drawing characters: How to print?
I ran the TREE command in the XP command prompt box and redirected the output to a text file.
But when I looked at the file in Notepad, Wordpad, and Word, the line drawing characters were rendered as upper case "A" characters with little doodads over the top of them (I've pasted the text at the end of this post).
I'm hopeing someone reading this might be able to point me to a Windows program that will run under XP or Win 7 that will correctly render those old DOS line drawing characters.
Will in Seattle
a.k.a. "Clueless"
P.S. Here's what the file looks like when I open it in Notepad:
Folder PATH listing for volume Insprion_C
Volume serial number is 7C91B304 CC4C:3DB7
C:.
ÃÄÄÄDell Laptop MP3s
³ ÃÄÄÄPlaylists
³ ³ ÃÄÄÄOrphanned Playlists
³ ³ ÀÄÄÄPlaylists from Buffalo
³ ÀÄÄÄRadio & Spoken Word, Dell 1150
ÃÄÄÄHarry Simeone Chorale - The Wonderful Songs Of Christmas
ÃÄÄÄMP3 INBOX on INSPIRON 1150
³ ÃÄÄÄEverything Learn French
³ ÃÄÄÄMINDFULNESS
³ ÃÄÄÄVirus Check
³ ³ ÀÄÄÄNormalize
³ ³ ÀÄÄÄTags
³ ³ ÃÄÄÄ2010AiC
³ ³ ÃÄÄÄAudition
³ ³ ³ ÀÄÄÄTransfer
³ ³ ÀÄÄÄTag Repair
³ ÀÄÄÄ_LEFTOVERS
ÃÄÄÄStokes Field Guide to Bird Songs
ÀÄÄÄ_INBOX Dell Laptop WAV files
But when I looked at the file in Notepad, Wordpad, and Word, the line drawing characters were rendered as upper case "A" characters with little doodads over the top of them (I've pasted the text at the end of this post).
I'm hopeing someone reading this might be able to point me to a Windows program that will run under XP or Win 7 that will correctly render those old DOS line drawing characters.
Will in Seattle
a.k.a. "Clueless"
P.S. Here's what the file looks like when I open it in Notepad:
Folder PATH listing for volume Insprion_C
Volume serial number is 7C91B304 CC4C:3DB7
C:.
ÃÄÄÄDell Laptop MP3s
³ ÃÄÄÄPlaylists
³ ³ ÃÄÄÄOrphanned Playlists
³ ³ ÀÄÄÄPlaylists from Buffalo
³ ÀÄÄÄRadio & Spoken Word, Dell 1150
ÃÄÄÄHarry Simeone Chorale - The Wonderful Songs Of Christmas
ÃÄÄÄMP3 INBOX on INSPIRON 1150
³ ÃÄÄÄEverything Learn French
³ ÃÄÄÄMINDFULNESS
³ ÃÄÄÄVirus Check
³ ³ ÀÄÄÄNormalize
³ ³ ÀÄÄÄTags
³ ³ ÃÄÄÄ2010AiC
³ ³ ÃÄÄÄAudition
³ ³ ³ ÀÄÄÄTransfer
³ ³ ÀÄÄÄTag Repair
³ ÀÄÄÄ_LEFTOVERS
ÃÄÄÄStokes Field Guide to Bird Songs
ÀÄÄÄ_INBOX Dell Laptop WAV files
Re: DOS TREE line drawing characters: How to print?
It's because TREE and Notepad use different character encodings.
If you would include option /a then TREE wouldn't use the box characters but the default ASCII |+-\ . If that is not sufficient we could try to convert the output (e.g. with a Batch - JScript hybrid code). Just tell us ...
Regards
aGerman
EDIT:
Try something like that (save as *.bat)
If you would include option /a then TREE wouldn't use the box characters but the default ASCII |+-\ . If that is not sufficient we could try to convert the output (e.g. with a Batch - JScript hybrid code). Just tell us ...
Regards
aGerman
EDIT:
Try something like that (save as *.bat)
Code: Select all
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
:: Batch part
@echo off &setlocal
set "outfile=tree.txt"
>"%outfile%" tree
for /f "tokens=2 delims=:" %%i in ('chcp') do set /a oemcp=%%~ni
cscript //E:JScript //nologo "%~fs0" "%oemcp%" "%outfile%"
exit /b
:: JScript part */
var streamASCII = WScript.CreateObject("ADODB.Stream");
streamASCII.Type = 2;
streamASCII.CharSet = "cp" + WScript.Arguments(0);
streamASCII.Open();
streamASCII.LoadFromFile(WScript.Arguments(1));
var streamUTF8 = WScript.CreateObject("ADODB.Stream");
streamUTF8.Type = 2;
streamUTF8.Charset = "utf-8";
streamUTF8.Open();
streamUTF8.WriteText(streamASCII.ReadText(-1));
streamUTF8.SaveToFile(WScript.Arguments(1), 2);
streamUTF8.Close();
streamASCII.Close();
Re: DOS TREE line drawing characters: How to print?
aGerman wrote:Try something like that (save as *.bat)
It works well here. :thumbsup:
Re: DOS TREE line drawing characters: How to print?
Using ADO streams is at least the easiest way I know to convert character encodings. You could take any charset providing the target charset supports all characters of the source file. That's the reason why I had to use UTF-8 above. The box characters are not part of the default ANSI (Windows-1252).
You will find a lot of the alias names in the registry
HKEY_CLASSES_ROOT\MIME\Database\Charset
But my experiences are that this list is incomplete and for OEM- (ASCII-, Batch-) code pages you can always use their numbers with CP prepended (e.g. "CP437" or "CP850").
Regards
aGerman
You will find a lot of the alias names in the registry
HKEY_CLASSES_ROOT\MIME\Database\Charset
But my experiences are that this list is incomplete and for OEM- (ASCII-, Batch-) code pages you can always use their numbers with CP prepended (e.g. "CP437" or "CP850").
Regards
aGerman
Re: DOS TREE line drawing characters: How to print?
I think the pure batch solution is more easy (only 2 lines of code per conversion).
But if you want to store it in UTF-8 then you have to first convert it to UTF-16 LE.
In addition you need the BOM (byte order marks) for UTF-16 LE and UTF-8.
You could create these files manually (using notepad), or you could use http://www.dostips.com/forum/viewtopic.php?f=3&t=5326, to do this automatically (-> ":createBom").
You only have to create them once, so it is no big problem to create them manually (only my point of view):
(Tested on WinXp 32 home.)
penpen
Edit: Replaced the local files names "UTF-16 LE BOM.txt" and "UTF-8 LE BOM.txt" (<- wrong too) with the files in the batch path; thanks to aGerman.
But if you want to store it in UTF-8 then you have to first convert it to UTF-16 LE.
In addition you need the BOM (byte order marks) for UTF-16 LE and UTF-8.
You could create these files manually (using notepad), or you could use http://www.dostips.com/forum/viewtopic.php?f=3&t=5326, to do this automatically (-> ":createBom").
You only have to create them once, so it is no big problem to create them manually (only my point of view):
Code: Select all
@echo off
setlocal enableExtensions enableDelayedExpansion
set "batchDir=%~dp0"
set "actualDir=%cd%"
set "Bom8File=%~dp0UTF-8 BOM.txt"
set "Bom16File=%~dp0UTF-16 LE BOM.txt"
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%~a"
:: create bom file if needed
if not exist "%Bom8File%" call :createBom "%Bom8File%" 239 187 191
if not exist "%Bom16File%" call :createBom "%Bom16File%" 255 254
:: convert to UCS-2 (subset of UTF-16 LE)
>nul copy /Y "%Bom16File%" tree16.txt
cmd /D /Q /U /C "(for /F "tokens=* delims=" %%a in ('tree.com') do echo(%%~a) >> "tree16.txt""
:: convert to UTF-8
>nul copy /Y "%Bom8File%" tree8.txt
cmd /D /Q /A /C ">nul chcp 65001 & cmd /D /Q /A /C type "tree16.txt" >>tree8.txt & >nul chcp %cp%"
endlocal
goto :eof
:createBom
setlocal enableExtensions enableDelayedExpansion
set "target="
set "params="
for %%N in (
%*
) do if not defined target ( set "target=%~1"
) else if not defined params ( set "params="%%~N""
) else ( set "params=!params! "%%~N""
)
if not defined target exit /b 1
if not defined params exit /b 1
REM This part of the batch file uses the result of the Topic on "www.dostips.com":
REM Create nul and all ascii characters with only batch
REM http://www.dostips.com/forum/viewtopic.php?f=3&t=5326
REM Teamwork of carlos, penpen, aGerman, dbenham, einstein1969
REM I only use the characters, needed: 0xEF, 0xBB, 0xBF, 0xFF, 0xFE
>"t.tmp" type nul
(
for %%N in (%params%) do if not exist "%%~N.chr" (
makecab /d compress=off /d reserveperfoldersize=%%~N /d reserveperdatablocksize=26 "t.tmp" "%%~N.chr"
type "%%~N.chr" | ((for /l %%I in (1 1 38) do pause)&(findstr "^">"temp.tmp"))
copy /y "temp.tmp" /a "%%~N.chr" /b
)
) > nul
>"%target%" type nul
for %%N in (%params%) do >nul copy /b "%target%" /b + "%%~N.chr" /b "%target%" /b
for %%N in (%params%) do if exist "%%~N.chr" del "%%~N.chr"
del "t.tmp", "temp.tmp"
endlocal
goto :eof
penpen
Edit: Replaced the local files names "UTF-16 LE BOM.txt" and "UTF-8 LE BOM.txt" (<- wrong too) with the files in the batch path; thanks to aGerman.
Last edited by penpen on 01 Sep 2014 16:13, edited 1 time in total.
Re: DOS TREE line drawing characters: How to print?
Good idea penpen
Please correct line 19 where you try to copy "UTF-8 LE BOM.txt". You created "UTF-8 BOM.txt" though.
In case the editor saves the Batch code in Windows-1252 (which should be usually true for the western hemisphere) you could simplify the creation of the BOM files. E.g.
Regards
aGerman

Please correct line 19 where you try to copy "UTF-8 LE BOM.txt". You created "UTF-8 BOM.txt" though.
In case the editor saves the Batch code in Windows-1252 (which should be usually true for the western hemisphere) you could simplify the creation of the BOM files. E.g.
Code: Select all
:createBom
>nul chcp 1252
<nul >"%Bom16File%" set /p "=ÿþ"
<nul >"%Bom8File%" set /p "="
>nul chcp %cp%
goto :eof
Regards
aGerman
Re: DOS TREE line drawing characters: How to print?
Nice
.
I haven't even thought about that
:
I have shortened the source code a little bit.
penpen

I haven't even thought about that

Code: Select all
:: Authors: aGerman, and penpen
:: Assumed: source codepage 1252
@echo off
setlocal enableExtensions disableDelayedExpansion
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%~a"
:: create bom for "tree16.txt" and "tree8.txt"
>nul chcp 1252
<nul >"tree16.txt" set /p "=ÿþ"
<nul > "tree8.txt" set /p "="
>nul chcp 850
:: convert to UCS-2 (subset of UTF-16 LE)
cmd /D /Q /U /C "(for /F "tokens=* delims=" %%a in ('tree.com') do echo(%%~a) >> "tree16.txt""
:: convert to UTF-8
cmd /D /Q /A /C ">nul chcp 65001 & cmd /D /Q /A /C type "tree16.txt" >>tree8.txt & >nul chcp %cp%"
endlocal
goto :eof
penpen
Re: DOS TREE line drawing characters: How to print?
Seems to work fine too guys.
tree16.txt and tree8.txt appear to look the same in notepad, in a simple test.
tree16.txt and tree8.txt appear to look the same in notepad, in a simple test.
Re: DOS TREE line drawing characters: How to print?
I've ran across this before.
If you want to preserve the nicer graphical characters, then you'll need to use a better text editor like notepad++ (or another one that supports displaying these characters. Or I believe you can try changing the font in Notepad to system or terminal or 8514oem if you have one of these and that might display them correctly.
If you just want to see the tree properly period, the /a switch is the easiest thing.
If you want to preserve the nicer graphical characters, then you'll need to use a better text editor like notepad++ (or another one that supports displaying these characters. Or I believe you can try changing the font in Notepad to system or terminal or 8514oem if you have one of these and that might display them correctly.
If you just want to see the tree properly period, the /a switch is the easiest thing.

Re: DOS TREE line drawing characters: How to print?
It is not really a font issue: It is a character encoding issue.
Notepad++ indeed is able to display such characters in the right way,
because it is able to to change the codepage to (for example) OEM 850.
But:
Notepad supports displaying characters like '├' (U+251C), just open tree8.txt or tree16.txt.
The only font that displays the desired result is "Terminal" (Small Font File: VGAOEM.FON; Large Font File: 8514OEM.FON),
because it bypasses the unicode translation, and it is the font known as "raster font" used by the command shell.
(And that is the reason why this font displays the right glyphs.)
No other font (shipped with windows) will show that result.
penpen
Notepad++ indeed is able to display such characters in the right way,
because it is able to to change the codepage to (for example) OEM 850.
But:
Notepad supports displaying characters like '├' (U+251C), just open tree8.txt or tree16.txt.
The only font that displays the desired result is "Terminal" (Small Font File: VGAOEM.FON; Large Font File: 8514OEM.FON),
because it bypasses the unicode translation, and it is the font known as "raster font" used by the command shell.
(And that is the reason why this font displays the right glyphs.)
No other font (shipped with windows) will show that result.
penpen
Re: DOS TREE line drawing characters: How to print?
The original notepad didn't have fonts, so it never had this problem. Like you said it is character encoding/decoding as notepad uses fonts to decode the characters.penpen wrote:It is not really a font issue: It is a character encoding issue.
Notepad++ indeed is able to display such characters in the right way,
because it is able to to change the codepage to (for example) OEM 850.
But:
Notepad supports displaying characters like '├' (U+251C), just open tree8.txt or tree16.txt.
The only font that displays the desired result is "Terminal" (Small Font File: VGAOEM.FON; Large Font File: 8514OEM.FON),
because it bypasses the unicode translation, and it is the font known as "raster font" used by the command shell.
(And that is the reason why this font displays the right glyphs.)
No other font (shipped with windows) will show that result.
penpen
Re: DOS TREE line drawing characters: How to print?
The (original) notepad within xp is able to change fonts.
You may select it clicking: [Menubar ->] Format -> Fonts.
penpen
You may select it clicking: [Menubar ->] Format -> Fonts.
penpen
Re: DOS TREE line drawing characters: How to print?
The original notepad I was referring owas Windows 3.0/3.1. Notepad was basically just a graphical text editor like edit back in those days.penpen wrote:The (original) notepad within xp is able to change fonts.
You may select it clicking: [Menubar ->] Format -> Fonts.
penpen

Re: DOS TREE line drawing characters: How to print?
Samir wrote:The original notepad I was referring owas Windows 3.0/3.1. Notepad was basically just a graphical text editor like edit back in those days.
I opened the notepad.exe from Win 3.11 under Windows 8 and it's true that it doesn't have the ability to set any font, but it doesn't display the line drawing characters from tree
Re: DOS TREE line drawing characters: How to print?
Sidenote: The win 3.11 notepad also uses fonts.
Actually i have no win 3.11 anymore (2 of the disks are damaged...),
but if i remember right, then it was possible to change the font used by notepad... and all other applications, that are using the "System" font.
But there is only one other possible (shipped with win 3.11): The "Terminal" font.
But this was not easy, and i don't remeber enough, maybe googling for this...:
You "only" have to copy "vga.drv" to "vgaT.drv" and hex edit "vgaT.drv".
I'm not sure anymore what and where to change exactly...
Maybe search null terminated String "System" and replace with null terminated String "Terminal"..., or was it a font number..., or both... couldn't remember anymore, sorry... .
And then you have to change the system.ini search the line with "vgasys.fon"
to "vga850.fon", and "vga.drv" to "vgaT.drv" :
I'm not sure with the number, the file should be within "windows\system".
penpen
Actually i have no win 3.11 anymore (2 of the disks are damaged...),
but if i remember right, then it was possible to change the font used by notepad... and all other applications, that are using the "System" font.
But there is only one other possible (shipped with win 3.11): The "Terminal" font.
But this was not easy, and i don't remeber enough, maybe googling for this...:
You "only" have to copy "vga.drv" to "vgaT.drv" and hex edit "vgaT.drv".
I'm not sure anymore what and where to change exactly...
Maybe search null terminated String "System" and replace with null terminated String "Terminal"..., or was it a font number..., or both... couldn't remember anymore, sorry... .
And then you have to change the system.ini search the line with "vgasys.fon"
to "vga850.fon", and "vga.drv" to "vgaT.drv" :
I'm not sure with the number, the file should be within "windows\system".
penpen