Skip to main content
TagQt provides a powerful template-based file renaming system that allows you to rename audio files based on their metadata tags.

Overview

The file renaming feature uses pattern templates with placeholders that are replaced with actual metadata values. This allows you to create consistent file naming schemes across your music library.

Available Template Patterns

The following template patterns are supported by the Renamer class:
PatternMetadata FieldDefault Value
%artist%ArtistUnknown Artist
%title%TitleUnknown Title
%album%AlbumUnknown Album
%year%Year(empty)
%track%Track Number(empty)
%genre%Genre(empty)
%albumartist%Album Artist(empty)
%bpm%BPM(empty)
%key%Initial Key(empty)

Common Patterns

Here are some commonly used naming patterns:

Pattern Examples

%artist% - %title%
→ Artist Name - Song Title.mp3

%track% %title%
→ 01 Song Title.mp3

%artist% - %album% - %track% - %title%
→ Artist Name - Album Name - 01 - Song Title.mp3

%albumartist%/%album%/%track% %title%
→ Album Artist/Album Name/01 Song Title.mp3

%year% - %album%/%track% - %artist% - %title%
→ 2024 - Album Name/01 - Artist Name - Song Title.mp3

Character Sanitization

The renamer automatically sanitizes filenames by replacing invalid characters with underscores: Invalid characters: \ / * ? " < > |
# Example from rename.py
re.sub(r'[\\/*?:"<>|]', '_', filename)
This ensures that generated filenames are valid across all operating systems.

Using the Renamer

From the Menu

  1. Navigate to Tools → File Actions → Rename Files
  2. Choose Selected or All Visible
  3. Enter your desired pattern in the dialog
  4. Preview the changes before applying

From the Command Palette

  1. Press Ctrl+K to open the command palette
  2. Search for “Rename Files”
  3. Select the command

From Context Menu

  1. Right-click on selected files
  2. Choose Rename Files (Selected)

Pattern Parsing

The renamer uses a sophisticated pattern parsing system:
# From rename.py:tag_to_filename
replacements = {
    '%artist%': metadata.artist or 'Unknown Artist',
    '%title%': metadata.title or 'Unknown Title',
    # ... more patterns
}

result = pattern
for key, value in replacements.items():
    result = result.replace(key, str(value))

Reverse Parsing (Filename to Tags)

The Renamer class also supports extracting metadata from filenames using the same pattern syntax:
# Example: filename_to_tag method
pattern = "%artist% - %title%"
filename = "Artist Name - Song Title"
# Returns: {'artist': 'Artist Name', 'title': 'Song Title'}
This feature uses regex to parse filenames and extract tag information based on the pattern template.

Best Practices

Always preview your renaming operations before applying them to ensure the pattern produces the expected results.
File renaming operations cannot be undone. Make sure you have backups of your music library before performing bulk rename operations.

Recommendations

  • Use track numbers with padding: Include %track% for proper sorting
  • Include artist and title: Essential for identification
  • Consider folder structure: Use / separators for organizing into subdirectories
  • Test on a small batch first: Preview and test your pattern on a few files before applying to your entire library

Technical Details

Source Code Reference

The file renaming functionality is implemented in:
  • Source: tagqt/core/rename.py (Renamer class)
  • Methods:
    • tag_to_filename(pattern, metadata) - Generates filename from pattern
    • sanitize_filename(filename) - Removes invalid characters
    • filename_to_tag(pattern, filename) - Extracts tags from filename

Implementation

The renaming operation is performed by the RenameWorker class, which:
  1. Validates the new filename
  2. Checks for conflicts
  3. Performs the rename operation
  4. Updates the file list in the UI
  5. Reports success or errors for each file

Build docs developers (and LLMs) love