BATCH_ Redirect special characters into file
ECHOing special characters like german umlauts in Batch or creating files with such in their name does not cause any trouble. However, when redirecting into files
Assuming that you are using a standard format for your textfiles, you can switch the encoding before redirection.
However, as you can see, the German output is ended with a dot, so that one is removed by converting the token to a number using SET /A. As that expression will work but give you a warning message about a missing operator (caused by the dot), redirection of error messages to NUL is added.
The rest ist simple: switching to standard text codepage 1252, redirecting and switching back to the original codepage.
DIR /B *.* > list.txt
these files will be created using the same codepage (or encoding) like the command line. However, as that codepage differs in most cases from the encoding that is used to read that file in external programs or editors, special characters are not being displayed correctly.Assuming that you are using a standard format for your textfiles, you can switch the encoding before redirection.
FOR /F "tokens=1* delims:" %%A IN ('CHCP') DO ( SET /A CODEPAGE = %%B 2> NUL ) CHCP 1252 > NUL DIR /B *.* > list.txt CHCP %CODEPAGE% > NULCHCP gives you the current codepage, however the output is localized (e.g. Active code page: 850 in English or Aktive Codepage: 850. in German). Therefore the tokens are delimited by the colon, which should work for most languages, I guess.
However, as you can see, the German output is ended with a dot, so that one is removed by converting the token to a number using SET /A. As that expression will work but give you a warning message about a missing operator (caused by the dot), redirection of error messages to NUL is added.
The rest ist simple: switching to standard text codepage 1252, redirecting and switching back to the original codepage.
cypressor - 28. Nov, 20:06