Automate Media File Organization for Plex
A well-organized Plex library means every file is in the right folder, named correctly, and free of duplicates or stale entries. Doing this manually for thousands of files is not sustainable. Automation tools handle the ongoing work — renaming new files to Plex conventions, maintaining folder structure, detecting duplicates, and cleaning up after deletions. This guide covers the tools and strategies for keeping a Plex library organized automatically.
Folder Structure Standards
Plex expects a specific folder hierarchy for each library type:
Movies
Each movie in its own folder:
/movies/Inception (2010)/Inception (2010).mkv/movies/The Dark Knight (2008)/The Dark Knight (2008).mkv
Include the year in both the folder and file name. This prevents mismatches when multiple movies share a title.
TV Shows
Series folder, season subfolders, episode files:
/tv/Breaking Bad/Season 01/Breaking Bad - S01E01 - Pilot.mkv/tv/Breaking Bad/Season 01/Breaking Bad - S01E02 - Cat's in the Bag.mkv
Music
Artist folder, album subfolder, track files:
/music/Pink Floyd/The Dark Side of the Moon/01 - Speak to Me.flac
Automated Renaming
Sonarr and Radarr
If you use Sonarr and Radarr for download management, they handle renaming automatically during import. Configure rename patterns in each tool under Settings then Media Management. Files are renamed before they reach the Plex library — no separate renaming step needed.
To rename existing files already in your library, use the Manual Import feature. Point it at your existing library directory and Sonarr or Radarr will match and rename files according to your configured pattern.
FileBot
FileBot is the standard standalone tool for batch renaming media files. It queries TMDB, TVDB, and other databases to identify files and renames them according to customizable patterns.
FileBot patterns for Plex:
- Movies:
{n} ({y})/{n} ({y})producesInception (2010)/Inception (2010).mkv - TV Shows:
{n}/Season {s.pad(2)}/{n} - {s00e00} - {t}
FileBot can be scripted for unattended operation. Create a script that watches a directory for new files, identifies them, and moves them into the correct library structure with proper naming.
Duplicate Detection
How Duplicates Happen
Duplicates accumulate through quality upgrades (old version not deleted), re-downloads, importing from multiple sources, or manual file management errors. They waste disk space and can confuse Plex's version selection.
Plex Built-In Detection
Plex identifies duplicates when multiple files match the same metadata entry. Browse a library and look for items with a version badge showing multiple files. Plex displays all versions and lets you choose which to keep.
Automated Duplicate Management
- Plex-Meta-Manager (PMM): Includes duplicate detection and reporting. Configure it to identify files matching the same metadata entry and generate reports with quality and size details.
- Custom scripts: Query the Plex API for all items in a library, group by title and year, and flag groups with more than one file. Output a report for manual review.
- fdupes: A filesystem-level tool that finds duplicate files by content hash. Useful for finding exact copies regardless of filename.
Always review before deleting duplicates. Apparent duplicates may be intentional — theatrical vs director's cut, or 1080p and 4K versions for different client capabilities.
Collection Management With PMM
Plex-Meta-Manager automates collection creation and maintenance:
- Franchise collections: Group all movies in a series (Marvel, Star Wars, Harry Potter) with custom artwork.
- Genre collections: Create collections by genre, populated automatically as new content is added.
- External list sync: Import from IMDB lists, Trakt trending, or Letterboxd lists on a schedule.
PMM runs on a schedule (typically daily) and updates all collections — adding new items that match and removing items that no longer qualify.
Metadata Cleanup
Unmatched Items
Files that Plex cannot match to any database entry show up with missing or generic metadata. Find them by sorting a library by date added and looking for items without poster art. Query the Plex API for items where the metadata agent returned no match to generate a list of problem files.
Stale Entries
When files are deleted from disk but Plex retains their database entries, the library accumulates items that cannot be played. Clean these with:
- Enable automatic Empty Trash in library settings — stale entries are removed during each scan.
- Run Empty Trash manually from Settings then Manage then Troubleshooting.
Cache Management
Plex caches poster art, backgrounds, and thumbnails. This cache grows over time, especially with chapter thumbnails enabled. Manage it by:
- Disabling chapter thumbnails for libraries where they add no value.
- Running Clean Bundles from Settings then Manage to remove cached data for deleted items.
- Running Optimize Database periodically to compact the database file.
Scheduled Maintenance
Combine all organization tasks into a single scheduled routine:
- Daily: PMM collection update, Plex library scan.
- Weekly: Duplicate scan and report, empty folder cleanup, database optimization, permission check.
- Monthly: Full metadata refresh, clean bundles, review unmatched items, storage usage report.
Empty Folder Cleanup
When files are moved or deleted, empty folders remain on disk. A scheduled script removes them:
On Linux: find /media -type d -empty -delete
On Windows, use a PowerShell script that recursively identifies and removes empty directories from the media root.
Permission Maintenance
Run a permission-fixing script after new content is added to ensure the Plex service user can read all files. Set directories to 755 and files to 644, with ownership matching the Plex service account.
Troubleshooting
Files Not Appearing in Plex
- Check file naming against Plex conventions. Incorrect naming is the most common cause of unmatched files.
- Verify file permissions allow the Plex service user to read the files.
- Run a manual library scan and check the Plex logs for scanning errors.
Wrong Metadata Match
- Use the Fix Match feature in Plex to search for the correct match.
- Include the year in the folder and file name to disambiguate titles.
- For stubborn mismatches, rename the file to exactly match the database title.