From 395de24346a831287e59af3c86f28b650591c123 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 13 Oct 2012 04:48:08 +0000 Subject: [PATCH] * Regular-expression based mass-rename utility, FileBot style! --- website/scripts/replace.groovy | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 website/scripts/replace.groovy diff --git a/website/scripts/replace.groovy b/website/scripts/replace.groovy new file mode 100644 index 00000000..71d15039 --- /dev/null +++ b/website/scripts/replace.groovy @@ -0,0 +1,24 @@ +// filebot -script fn:replace --action copy --filter [.]srt$ --def e=[.](eng|english) r=.en + +// imports +import net.sourceforge.filebot.StandardRenameAction + +// parameters +def action = StandardRenameAction.forName(_args.action) +def accept = { f -> _args.filter ? f.path =~ _args.filter : true } + +// rename +args.getFiles{ accept(it) }.each{ + if (it.path =~ e) { + def nfile = new File(it.path.replaceAll(e, r)) + + // override files only when --conflict override is set + if (!it.equals(nfile)) { + if ((nfile.exists() || _args.conflict == 'override') && action != StandardRenameAction.TEST) { + nfile.delete(); // resolve conflict + } + + println action.rename(it, nfile) + } + } +}