Reputation: 63
How can I convert a directory of pre-existing text from Unicode to ANSI with a batch file? Is there some tool that I can use to loop through the files and perform the conversion?
Upvotes: 4
Views: 13139
Reputation: 130919
EDIT - The following will convert UTF-16 with BOM. I don't think it works with any of the other UTF formats. I know it doesn't work for UTF-8. I'm not sure about UTF-32 with BOM
for %%F in (*.txt) do type "%%F" >"%%~nF.converted"
If run from the command line then use single percent %
instead of double percent %%
.
After you verify the converted files are correct, you can
del *.txt
ren *.converted *.txt
Upvotes: 5
Reputation: 28707
See https://superuser.com/questions/27060/batch-convert-files-for-encoding-or-line-ending. Specifically, iconv looks exactly like what you're looking for.
You're looking for the reverse of the example posted there, so you'd want something like this:
$ iconv -f utf-8 -t windows-1252 infile > outfile
Upvotes: 5