Last active
March 13, 2017 20:39
-
-
Save rupertbates/b3d45e382c035ec4247255f69289df48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This script fixes the naming on some video files which were numbered wrong - The last file 2x8 was actually the first | |
//and all the others were one down from where they should be (2x1 was actually the second 2x2 etc.) | |
//I have run it on the second series (2xX) but none of the others | |
import ammonite.ops._ | |
val dir = home/'Movies/"Sapphire and Steel (1979-82 ITV)" | |
//get a list of the files in a particular series | |
val seriesNumber = 2 | |
val series = (ls! dir).filter(x => x.name.contains(seriesNumber + "x")) | |
//regex to find the episode number | |
val regex = "x(\\d)".r | |
//move all the filenames up 1 episode number | |
series.reverse.map(f => mv(f, dir/regex.replaceAllIn(f.name, m => "x" + (m.group(1).toInt + 1).toString))) | |
//get a list of the files with their new names | |
val series = (ls! dir).filter(x => x.name.contains(seriesNumber + "x")) | |
val last = series.reverse.head | |
//move the last one first | |
mv(last, dir/regex.replaceAllIn(last.name, m => "x1")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment