5

I want to list the contents of my directories and sub-directories in a file, but the contents of the sub-directories have Russian titles. How can I do that? If I list the contents in the command prompt window the list shows correctly. This works.

> dir /s

But if I try to save the list in a document the cyrillic renders as question marks. This doesn't work.

> dir /s > myFiles.txt
HGamble
  • 415
  • 5
  • 17
  • 2
    See if this helps? https://superuser.com/questions/1302096/files-with-non-ascii-characters-in-file-name-in-a-windows-batch-file – Tarun Lalwani Jul 22 '19 at 12:23

2 Answers2

6

If I recall correctly, under windows, you have to do two things to gain full unicode (and thus cyrillic) font support:

  1. Change the console code page to UTF-8 by chcp 65001, see Manpage of chcp.
  2. Ensure that your command line uses a font that supports UTF-8, for instance Lucida Console, there is a lengthy description how to do that

Related question(s)

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • The problem is not with using Cyrillic letters in my command line. I can navigate to folders with Cyrillic names, and make new files with Cyrillic names. So these all work fine: > cd юлия > echo тестюлия > тестюлия.txt But the content of the text file is not "тестюлия", but a series of question marks. – HGamble Jul 25 '19 at 18:21
  • I tried using chcp 65001, and also chcp 855 and 866, but it didn't make any difference in the output. The contents of the folder are still listed incorrectly. – HGamble Jul 25 '19 at 18:26
  • Do you have an editor like `notepad++` where you can actively change the encoding and try different ones? Auto-detect might went wrong in your editor, there are other cyrillic encodings other than UTF-8. – B--rian Jul 26 '19 at 17:14
  • 1
    If I do type myFiles.txt then all the files are listed in the command prompt window and the character encoding is incorrect. – HGamble Jul 26 '19 at 17:48
  • I have tried to change the encoding in notepad++ and it doesn't make a difference. – HGamble Jul 26 '19 at 17:49
  • But, you mentioned PowerShell, and that gave me an idea. I decided to try with GitBash instead of Windows Command Prompt, and it worked! Saving the directories and sub-directories as a txt file resulted in proper character encoding, but one long string of data. Saving in a doc file worked well.Used $ ls -R >myFiles.doc – HGamble Jul 26 '19 at 18:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197062/discussion-between-hgamble-and-b-rian). – HGamble Jul 26 '19 at 18:59
2

One workaround is to download a Unix shell command line interface. I used Git Bash.

ls -R > myFiles.doc

All my files are listed correctly in the Cyrillic font.

HGamble
  • 415
  • 5
  • 17