How can I batch-convert files in a directory for their encoding (e.g. ANSI → UTF-8) with a command or tool?
For single files, an editor helps, but how can I do the mass files job?
batchencodinglinuxmacoswindows
How can I batch-convert files in a directory for their encoding (e.g. ANSI → UTF-8) with a command or tool?
For single files, an editor helps, but how can I do the mass files job?
Best Answer
Cygwin or GnuWin32 provide Unix tools like
iconv
anddos2unix
(andunix2dos
). Under Unix/Linux/Cygwin, you'll want to use "windows-1252" as the encoding instead of ANSI (see below). (Unless you know your system is using a codepage other than 1252 as its default codepage, in which case you'll need to tell iconv the right codepage to translate from.)Convert from one (
-f
) to the other (-t
) with:Or in a find-all-and-conquer form:
Alternatively:
This question has been asked many times on this site, so here's some additional information about "ANSI". In an answer to a related question, CesarB mentions:
The page he links to gives this historical tidbit (quoted from a Microsoft PDF) on the origins of CP 1252 and ISO-8859-1, another oft-used encoding: