Convert ANSI to UTF16LE

Duke 21 Reputation points
2022-07-30T09:28:58.197+00:00

I created a file list text file via the DOS command dir [<drive>:][<path>][<filename>] [...] [/p] [/q] [/w] [/d] [/a[[:]<attributes>]][/o[[:]<sortorder>]] [/t[[:]<timefield>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] [/r], the generated text file is on encoding ANSI, and it causes a problem, the Chinese characters in that text file cannot be read by a third application's script language. It requires the text file is on encoding UTF16LE.
I can convert that text file from ANSI to UTF16LE manually, but I want to find a DOS command that can do this job. or find a way to change the default encoding of the text file generated by the DOS command dir [<drive>:][<path>][<filename>] [...] [/p] [/q] [/w] [/d] [/a[[:]<attributes>]][/o[[:]<sortorder>]] [/t[[:]<timefield>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] [/r].

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,260 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 11,621 Reputation points
    2022-07-30T12:35:21.45+00:00

    You can use the GetContent in Powershell to read the file and use SetContent to write it to another file with another encoding.

    e.g.

    (Get-Content -path '...path to source file') | Set-Content -Encoding Unicode -path 'path to target file'

    Refer: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-7.2

    Hope this helps


0 additional answers

Sort by: Most helpful