Skip to content

Instantly share code, notes, and snippets.

@MCOfficer
Created November 3, 2017 14:25
Show Gist options
  • Save MCOfficer/cd52764b75282aef79c0a5ca1902410a to your computer and use it in GitHub Desktop.
Save MCOfficer/cd52764b75282aef79c0a5ca1902410a to your computer and use it in GitHub Desktop.
[Python] camelCaseFilenames_to_underscore_filenames_(uncapitalized) - recursive, and renames itself ¯\_(ツ)_/¯
import re
import glob
import os
import os.path
def camelCaseSplit(identifier):
matches = [m.group(0) for m in re.finditer('.+?(?:(?<=[a-z])(?=[_A-Z])|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)', identifier)]
s = matches[0]
for i in range(1, len(matches)):
if matches[i][0] == "_":
s += matches[i].lower()
else:
x = "_" + matches[i].lower()
s += x
print(s)
return s
for f in glob.iglob(os.getcwd() + "/**/*", recursive=True):
name, dummy = os.path.splitext(f)
os.rename(f, f.replace(name, camelCaseSplit(name)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment