Mobilpadde
Mobilpadde

Reputation: 1881

Rename every other file

I have quite some files I'd like to get renamed (Too many to do it manually), normally I'd use Automator but the thing is, I need every other file to be called the same as the file before it, but with a 2 instead of 1

This is my files so far

xxx - 401a - yyy.zzz
xxx - 401b - yyy.zzz
xxx - 402a - yyy.zzz
xxx - 402b - yyy.zzz
xxx - 403a - yyy.zzz

And so on, but I'd like to rename them to something like

xxx - 401-pt1.zzz
xxx - 401-pt2.zzz
xxx - 402-pt1.zzz
xxx - 402-pt2.zzz
xxx - 403-pt1.zzz

Anyway to do this with automator? Asking because I've really rarely use Automator, meaning I'm not exactly what you'd call an expert.

EDIT: This is what I'm trying to achieve: http://wiki.plexapp.com/index.php/Media_Naming_and_Organization_Guide#Stacked_Episodes

Upvotes: 0

Views: 407

Answers (1)

Sébastien Dawans
Sébastien Dawans

Reputation: 4626

If you don't know anything about that tool than you won't mind using something else? How about a simple shell command?

Here is the same operation in Bash in increasing level of genericity. You probably don't care for the first two as it has hardcoded yyy's and zzz's but I did it to show you around the sed command a bit to understand the third one.

for file in * ; do mv "$file" "$(echo $file | sed 's/a - yyy/-pt1/g')"; mv "$file" "$(echo $file | sed 's/b - yyy/-pt2/g')"; done

for file in * ; do mv "$file" "$(echo $file | sed 's/a - .*.zzz/-pt1.zzz/g')"; mv "$file" "$(echo $file | sed 's/b - .*.zzz/-pt2.zzz/g')"; done

for file in * ; do mv "$file" "$(echo $file | sed -r 's/a - .*.([a-z]{3})/-pt1.\1/')"; mv "$file" "$(echo $file | sed -r 's/b - .*.([a-z]{3})/-pt2.\1/')"; done

There must be many other ways with other commands, of course. You'll get unimportant errors because the mv is done twice on the whole batch.

Upvotes: 2

Related Questions