-
-
Save bjverde/88bbc418e79f016a57539c2d5043c445 to your computer and use it in GitHub Desktop.
Convert multiple files to UTF-8 encoding with Notepad++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2016-2017 Soverance Studios. | |
# Scott McCutchen | |
# This file will search all files and folders within a given directory, and use Notepad++ to convert their encoding to UTF-8 without Byte Order Marks | |
# | |
# This file must be run using the PythonScript plugin from within Notepad++, which is available through the Notepad++ Plugin Manager | |
# | |
# You must have Python 2.7 installed | |
# | |
# Additionally, this script can only exist and be run from within the Notepad++ user's working directory, the default of which is here: | |
# Note that selecting "New Script" from within the PythonScript plugin will automatically default to this save location | |
# | |
# .. USER DIRECTORY\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts | |
# | |
# WARNING !! This script will work if Notepad ++ is in ANY Lang. To use in your native language use the terms of the translation | |
import os; | |
import sys; | |
from Npp import notepad | |
filePathSrc="D:\\wamp\www\\formDin\\base" # Path to the folder with files to convert | |
for root, dirs, files in os.walk(filePathSrc): | |
for fn in files: | |
if fn[-4:] == '.php' or fn[-4:] == '.inc' or fn[-4:] == '.css' or fn[-4:] == '.js' or fn[-4:] == '.htm' or fn[-4:] == '.html': # Specify file types, taking care to change the fn[number] to correspond to length of the file's extension including the . | |
notepad.open(root + "\\" + fn) | |
console.write(root + "\\" + fn + "\r\n") | |
#notepad.runMenuCommand("Encoding", "Convert to UTF-8 without BOM") | |
notepad.menuCommand(MENUCOMMAND.FORMAT_CONV2_AS_UTF_8) | |
notepad.save() | |
notepad.close() |
How to add win 1251 file names reading for script ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A version to convert every currently opened tabs:
#Note: pay attention to the 'AS' and 'CONV2' in the enum names!!
#notepad.menuCommand(MENUCOMMAND.FORMAT_CONV2_AS_UTF_8) #to UTF8 without BOM
#notepad.menuCommand(MENUCOMMAND.FORMAT_AS_UTF_8) #to UTF8 without BOM
#notepad.menuCommand(MENUCOMMAND.FORMAT_CONV2_UTF_8) #to UTF8-BOM