1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 09:18:51 -05:00
filebot/website/scripts/replace.groovy
2012-10-14 04:30:52 +00:00

25 lines
695 B
Groovy

// 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)
}
}
}