batch-fileio-redirectionextended-ascii

Batch files - why does a funny ASCII character appear when redirecting output of tree command to a file?


The following code:

if "%DispMode%"=="tree" (
 tree >temp
 findstr /b /v /c:"F" temp >>temp2
 del temp >nul
 findstr /b /v /c:"V" temp2 >>temp
 del temp2 >nul
 findstr /b /v /c:"A" temp >>temp2
 del temp >nul
 type temp2
 del temp2 >nul
)

...for some reason outputs a funny ASCII character at the beginning of the line of each non-root folder and in other places too. The character looks like a superscript, underlined a. I'm hoping someone can explain why this is happening?

I was able to produce this problem even by just typing tree >tempfile at the Win11 command prompt and then type tempfile, so I don't think this has anything to do with the block of code, the findstr commands, or whatever.


Solution

  • The extended ascii-characters used by tree are causing your weird characters. Different character sets show different characters for these extended characters. Use Tree /A to circumvent this problem.