3
2
I wanted to automate the creation of a directory tree file in Windows 10.
In PowerShell, I executed the following commands:
cd C:\TreeTest
tree /f > .\TreeStructure.txt
The output was a pretty UTF-8 file:
Now I wanted to do the same thing in a batch file:
@echo off
cd C:\TreeTest
tree /f > .\TreeStructure.txt
But the output from the batch file execution had the encoding screwed up:
Why is the encoding of the PowerShell output different from the output of the batch file?
I know that I can get an ASCII output by adding /a to the tree command, but I would prefer the pretty UTF-8 output to be saved to my tree file.
I tried changing the codepage by adding "chcp 65001" to my batch file, but it didn't change the file output.
Command Prompt “tree” shows Unicode in console but outputs to file in ASCII, Saving 'tree /f /a" results to a textfile with unicode support – phuclv – 2019-11-18T16:29:29.833