Skip to content

Instantly share code, notes, and snippets.

@bjverde
Last active February 23, 2022 07:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjverde/583c2ee8b386994f3a1f8acdea3b7ed2 to your computer and use it in GitHub Desktop.
Save bjverde/583c2ee8b386994f3a1f8acdea3b7ed2 to your computer and use it in GitHub Desktop.
Convert multiple files to Unix Formart EOL with Notepad++
# 2020-06-07
# 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 only work if Notepad ++ is in English. To use in your native language use the terms of the translation
#
# PythonScript Site - http://npppythonscript.sourceforge.net/download.shtml
# PythonScript Documentation - http://npppythonscript.sourceforge.net/docs/latest/
# PythonScript Forum - https://sourceforge.net/p/npppythonscript/discussion/
#
#ConvertEolUnix.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:] == '.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("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