Skip to content

Instantly share code, notes, and snippets.

@dfrankland
Created December 24, 2014 19:55
Show Gist options
  • Save dfrankland/92d49c90ce67b827db7e to your computer and use it in GitHub Desktop.
Save dfrankland/92d49c90ce67b827db7e to your computer and use it in GitHub Desktop.
Font Rename Files
import os
import shutil
import re
def changeFileName(files):
for file in files:
name = file.split("-")
extension = name[2].split(".")[1]
newFileName = ".".join([name[1],extension])
os.renames(file, newFileName)
def getFilesWith(extension):
files = []
for file in [file for file in os.listdir('.') if os.path.isfile(file)]:
if file.endswith(extension):
files.append(file)
return files
if __name__ == "__main__":
if not os.path.exists("renamed_files"):
os.makedirs("renamed_files")
for file in getFilesWith(".woff"):
shutil.copy(file,"renamed_files")
for file in getFilesWith(".svg"):
shutil.copy(file,"renamed_files")
os.chdir("renamed_files")
changeFileName(getFilesWith(".woff"))
changeFileName(getFilesWith(".svg"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment