Change files' encoding recursively on Windows?

后端 未结 5 1292
小鲜肉
小鲜肉 2020-12-08 07:50

Does anybody know a tool, preferably for the Explorer context menu, to recursively change the encoding of files in a project from ISO-8859-1 to UTF-8 and other encodings? Fr

5条回答
  •  北海茫月
    2020-12-08 08:31

    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.txt
    echo %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.

提交回复
热议问题