Skip to content

Instantly share code, notes, and snippets.

@rupertbates
Last active March 13, 2017 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupertbates/b3d45e382c035ec4247255f69289df48 to your computer and use it in GitHub Desktop.
Save rupertbates/b3d45e382c035ec4247255f69289df48 to your computer and use it in GitHub Desktop.
//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