diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 8be890cc..1f2b4922 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; @@ -341,18 +340,19 @@ public abstract class ScriptShellBaseClass extends Script { } public List rename(Map parameters) throws Exception { + // consume all parameters List files = getInputFileList(parameters); + Map map = files.isEmpty() ? getInputFileMap(parameters) : emptyMap(); // check map parameter if file/folder is not set RenameAction action = getRenameAction(parameters); ArgumentBean args = getArgumentBean(parameters); try { if (files.size() > 0) { return getCLI().rename(files, args.getRenameAction(), args.getConflictAction(), args.getAbsoluteOutputFolder(), args.getExpressionFormat(), args.getDatasource(), args.getSearchQuery(), args.getSortOrder(), args.getExpressionFilter(), args.getLanguage().getLocale(), args.isStrict()); - } else { - Map map = getInputFileMap(parameters); - if (map.size() > 0) { - return getCLI().rename(map, action, args.getConflictAction()); - } + } + + if (map.size() > 0) { + return getCLI().rename(map, action, args.getConflictAction()); } } catch (Exception e) { printException(e); @@ -484,9 +484,17 @@ public abstract class ScriptShellBaseClass extends Script { private Map getInputFileMap(Map parameters) { // convert keys and values to files - Function mapping = f -> asFileList(f).iterator().next(); + Map map = new LinkedHashMap(); - return consumeParameter(parameters, "map").map(Map.class::cast).collect(toMap(mapping, mapping, (a, b) -> a, LinkedHashMap::new)); + consumeParameter(parameters, "map").map(Map.class::cast).forEach(m -> { + m.forEach((k, v) -> { + File from = asFileList(k).get(0); + File to = asFileList(v).get(0); + map.put(from, to); + }); + }); + + return map; } private RenameAction getRenameAction(Map parameters) {