Skip to content

Instantly share code, notes, and snippets.

@me-suzy
Last active July 26, 2022 20:27
Show Gist options
  • Save me-suzy/4ab83b97e85b29302746fbdc51a03427 to your computer and use it in GitHub Desktop.
Save me-suzy/4ab83b97e85b29302746fbdc51a03427 to your computer and use it in GitHub Desktop.
How to make a batch processor with multiple search and replace on notepad++ (you can also use regex for search and replace)
How to make a batch processor with multiple search and replace on notepad++.
This code works with Python Script Plugon on notepad++. Save this code as .py, and copy it in c:\Program Files\Notepad++\plugins\PythonScript\scripts\
Use Menu -> Plugins -> Python Script -> Scripts -> THIS-SCRIPT.py
Remember to change the path on the script, the location of folder where you want to change all files: Path="C:\\python-test"
-------------------------------------------------------------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
from __future__ import print_function
from Npp import *
import os
import sys
#-------------------------------------------------------------------------------
class T22601(object):
def __init__(self):
Path="C:\\python-test"
for root, dirs, files in os.walk(Path):
nested_levels = root.split('/')
if len(nested_levels) > 0:
del dirs[:]
for filename in files:
if filename[-5:] == '.html':
notepad.open(root + "\\" + filename)
console.write(root + "\\" + filename + "\r\n")
notepad.runMenuCommand("Encodage", "Convertir en UTF-8")
regex_find_repl_dict_list = [
{ 'find' : '<title>(.*?)</title>', 'replace' : r'\3\2\1' },
{ 'find' : '<head>\s+', 'replace' : r'\n baba ' },
]
editor.beginUndoAction()
for d in regex_find_repl_dict_list: editor.rereplace(d['find'], d['replace'])
editor.endUndoAction()
notepad.save()
notepad.close()
#-------------------------------------------------------------------------------
if __name__ == '__main__': T22601()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment