Skip to content

Instantly share code, notes, and snippets.

@bjverde
Created September 4, 2020 04:45
Show Gist options
  • Save bjverde/028c8cc32ea1d66679320fb73c4d413c to your computer and use it in GitHub Desktop.
Save bjverde/028c8cc32ea1d66679320fb73c4d413c to your computer and use it in GitHub Desktop.
# 2020-09-04
# Reinaldo A. Barreto Jr
#
# This file will search all files and folders within a given directory, and use Notepad++ to convert their EOL to UNIX.
# Based on the script of ConvertUTF-8.py de Scott McCutchen
#
# 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
#convert2Utf8AndEolUnix.py
import os;
import sys;
from Npp import notepad
filePathSrc="D:\\wamp\www\\formDin5" # Path to the folder with files to convert
console.write(filePathSrc + "\r\n")
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] == '.asp' or fn[-4:] == '.php' or fn[-4:] == '.inc' or fn[-4:] == '.css' or fn[-4:] == '.js' or fn[-4:] == '.htm' or fn[-5:] == '.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")
# 2 Ways to convert To Unix Format
# https://sourceforge.net/p/npppythonscript/discussion/1188886/thread/ff10aecc/?limit=25
#notepad.runMenuCommand("Encoding", "Convert to UTF-8 without BOM")
notepad.menuCommand(MENUCOMMAND.FORMAT_CONV2_AS_UTF_8)
#notepad.runMenuCommand("EOL Conversion", "Unix (LF)")
notepad.menuCommand(MENUCOMMAND.FORMAT_TOUNIX)
#notepad.setFormatType(FORMATTYPE.UNIX) # This way does not convert
notepad.save()
notepad.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment