windows - Batch change encoding ascii files from utf-8 to iso-8859-1

25
2014-03
  • Enrique

    Possible Duplicate:
    Batch-convert files for encoding or line ending under Windows

    I need a tool like this
    http://www.rotatingscrew.com/utfcast.aspx

    But the tool should do the opposite, convert multiple files from utf-8 to iso-8859-1

    Is there any tool (php script, batch file, etc.) for Windows that can do this? Thanks

  • Answers
  • John T

    You can use iconv from GNUWin32, it works the same as the GNU/Linux counterpart:

    iconv -f UTF-8 -t ISO-8859-1 filename.txt
    

    you can then use it with batch, provided you've added it to your %PATH%:

    for /f %x in ('dir /b *.txt') do iconv -f UTF-8 -t ISO-8859-1 %x
    
  • David R Tribble

    I wrote a DOS/Windows shell utility to do this. The source code is open source C++, so it can be ported to other systems.

    Look for crlf.cppat david.tribble.com/src/src.html
    The executable is at david.tribble.com/programs.html

  • Sathya

    ConvertEncoding link is now dead - use either of these programs which will encode the files for you:


  • Related Question

    linux - How can I convert multiple files to UTF-8 encoding using *nix command line tools?
  • jason

    Possible Duplicate:
    Batch-convert files for encoding or line ending

    I have a bunch of text files that I'd like to convert from any given charset to UTF-8 encoding.

    Are there any command line tools or Perl (or language of your choice) one liners I can use to do this en masse?


  • Related Answers
  • grawity

    iconv does convert between many character encodings. So adding a little bash magic and we can write

    for file in *.txt; do
        iconv -f ascii -t utf-8 "$file" -o "${file%.txt}.utf8.txt"
    done
    

    This will run iconv -f ascii -t utf-8 to every file ending in .txt, sending the recoded file to a file with the same name but ending in .utf8.txt instead of .txt.

    It's not as if this would actually do anything to your files (because ASCII is a subset of UTF-8), but to answer your question about how to convert between encodings.