Skip to content

Instantly share code, notes, and snippets.

@LulaSvob
Forked from smccutchen/ConvertUTF-8.py
Last active September 20, 2018 06:52
Show Gist options
  • Save LulaSvob/8d78095c528eaed7c1f32ff621221741 to your computer and use it in GitHub Desktop.
Save LulaSvob/8d78095c528eaed7c1f32ff621221741 to your computer and use it in GitHub Desktop.
Convert multiple files to UTF-8 encoding with Notepad++ with non-Latin (Cyrillic) path
# -*- coding: utf-8 -*-
# 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
import os
import sys
from Npp import notepad
filePathSrc = "D:\\Файлове\\" # Path to the folder with files to convert
filePathSrc = filePathSrc.decode('utf-8')
os.chdir(filePathSrc)
for root, dirs, files in os.walk(".", topdown = False):
for fn in files:
if fn[-4:] == '.txt': # or fn[-4:] == '.cpp': # 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)
notepad.runMenuCommand("Encoding", "Convert to UTF-8")
notepad.save()
console.write('File ' + fn + ' saved. Closing ... \n')
notepad.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment