How do I convert file encodings through the command line?
Use the following command line options:
/cp "encoding" | Sets an encoding to open as |
/cps "encoding" | Sets an encoding to open as |
/sa "DestFile" | Specifies a file name to save as after the encoding conversion |
/ss+ | Saves the file with a Unicode signature (BOM) after the encoding conversion |
/ss- | Saves the file without a Unicode signature (BOM) after the encoding conversion |
For instance, if you want to convert a file from Western European (iso-8859-1) to UTF-8, use the following syntax:
emeditor.exe "windows1252.txt" /cp 1252 /cps 65001 /ss- /sa "utf8.txt"
See Encoding Constants for the list of encodings.
See Using Command Line Options for more information.
Convert multiple files with a script
We can use this PowerShell script to quickly convert all files in a directory. Open PowerShell and enter cd 'your folder path'
, to go to the folder which contains your files. Now enter the following lines.
$files = (Get-ChildItem -File).FullName $files | foreach { emeditor $_ /cp 65001 /cps 65537 /ss- /sa $_ }
(Get-ChildItem -File).FullName
returns an array of all file paths in the current directory. For each file, we apply the command from before to convert all files from UTF-8 to UTF-16.