Change files' encoding recursively on Windows? Change files' encoding recursively on Windows? windows windows

Change files' encoding recursively on Windows?


You could easily achieve something like this using Windows PowerShell. If you got the content for a file you could pipe this to the Out-File cmdlet specifying UTF8 as the encoding.

Try something like:

Get-ChildItem *.txt -Recurse | ForEach-Object {$content = $_ | Get-ContentSet-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force}  


I don't know about from the context menu, but notepad++ allows you to change file encodings and it has a macro option... so you could automate the process


If you import a test.reg file having the following contain

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\Directory\shell\ConvertPHP]@="convert all .php files to UTF-8"[HKEY_CLASSES_ROOT\Directory\shell\ConvertPHP\command]@="cmd.exe /c C:\\TEMP\\t.cmd php \"%1\""

After this you will receive the menu item "convert all .php files to UTF-8" in the context menu of explorer on every directory. After the choosing of the item the batch program C:\TEMP\t.cmd will be started with "php" string as the first parameter and the quoted directory name as the second parameter (of cause the first parameter "php" you can skip if it is not needed). The file t.cmd like

echo %1>C:\TEMP\t.txtecho %2>>C:\TEMP\t.txt

can be used to prove that all this work.

So you can decode the *.php files with any tool which you prefer. For example you can use Windows PowerShell (see the answer of Alan).

If you want that the extension like PHP will be asked additionally you can write a small program which display the corresponding input dialog and then start the Windows PowerShell script.