I am trying to rearrange several filenames of varying lengths with Krename. I need the last 10 digits(for example 2018-06-09) moved to the middle of the filename. I cant figure out how to select the last 10 digits from multiple filenames as it seems that I can only count from the beginning to the end of the filename and not from the end to the beginning. So different lengths of filenames produce different unwanted results.
For example, I have some files:
The Regular Show Xtra Regular 2018-06-09.mp4 and
The Regular Show This title is much longer 2019-05-03.mp4
I would like to put the date after the title of the show but before the title of the episode. So:
The Regular Show 2018-06-09 Xtra Regular.mp4
The Regular Show 2019-05-03 This title is much longer.mp4
Anyone know how to do this? I have a few hundred files….
I use Plex, so actual filenames aren’t usually too critical like that… however, for this kind of manipulation you’d do better with a shell script to rip the last ten characters and stick them in at the start of the file.
After that, you can delete any parts you don’t want, and add the title before the date if that works… so aiming for ‘The Regular Show S01E03 2018-04-30.mp4’ or something like that.
for file in *.mp4; do
# Get everything except the extension
name="${file%.mp4}"
# Extract last 10 characters (assuming they're the date)
date="${name: -10}"
# Get the rest of the name
title="${name:0:$((${#name}-10))}"
# Rename
mv "$file" "${date} - ${title}.mp4"
done