Skip to content

Instantly share code, notes, and snippets.

@bjverde
Forked from smccutchen/ConvertUTF-8.py
Last active July 12, 2024 13:40
Show Gist options
  • Save bjverde/88bbc418e79f016a57539c2d5043c445 to your computer and use it in GitHub Desktop.
Save bjverde/88bbc418e79f016a57539c2d5043c445 to your computer and use it in GitHub Desktop.
Convert multiple files to UTF-8 encoding with Notepad++
# 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()
@masterwishx
Copy link

How to add win 1251 file names reading for script ?

@masterwishx
Copy link

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment