# Automatically Renaming Video Files For Plex
## Rename Title Script
The idea with this is to take an existing folder with subfolders of TV show episodes, and reformat them as such:
`S04E13 - The Nightman Cometh.mp4` -> `The Nightman Cometh - S04E13.mp4`
This is so [[Plex]] knows how to organize the episodes into a parent show.
```python
import os
import re
def rename_files_in_directory(root_dir):
pattern = re.compile(r'^(S\d{2}E\d{2}) - (.+?)(\..+)