The fastest way is to use a Python script to edit the .ttf files. This script here prepends, appends, or renames the font filename, the font name, and doesn't rename font files that have already been renamed. Use pip install fontTools and then run the script python rename_fonts.py inside the directory with font files. ctrl-f "Free", make your edits, and then batch rename all files in the directory where the script is.
# Example Usage
# python rename_font.py
# rename all .ttf font files in this directory and sub-directories to "Free {original name}" and the font name to "Free {og name}"
import os
import sys
from fontTools.ttLib import TTFont
def rename_font(input_path):
filename = os.path.basename(input_path)
dirname = os.path.dirname(input_path)
if filename.startswith("Free "):
print(f"Skipping already renamed font: {filename}")
return
font = TTFont(input_path)
name_ids_to_update = [1, 4, 6, 16, 17] # Update key name IDs
original_name = None
for record in font["name"].names:
if record.nameID == 1: # Family Name
try:
encoding = "utf-16-be" if record.platformID == 3 else record.getEncoding()
original_name = record.string.decode(encoding)
break
except Exception:
continue
if not original_name:
original_name = os.path.splitext(filename)[0]
if original_name.startswith("Free"):
new_filename = f"Free {filename}"
new_path = os.path.join(dirname, new_filename)
os.rename(input_path, new_path)
print(f"Renamed file to match font name: {new_filename}")
return # Skip further processing
new_name = f"Free {original_name}" # Prepend "Free"
for record in font["name"].names:
if record.nameID in name_ids_to_update:
try:
encoding = "utf-16-be" if record.platformID == 3 else record.getEncoding()
record.string = new_name.encode(encoding)
except Exception as e:
print(f"Error updating nameID {record.nameID} for {input_path}: {e}")
output_path = os.path.join(dirname, f"Free {filename}")
font.save(output_path)
print(f"Renamed font saved as: {output_path}")
def find_and_rename_fonts(directory):
for root, _, files in os.walk(directory):
for file in files:
if file.lower().endswith(".ttf"):
font_path = os.path.join(root, file)
rename_font(font_path)
if name == "main":
target_directory = sys.argv[1] if len(sys.argv) > 1 else "."
find_and_rename_fonts(target_directory)