From d61695b42657a421f0c4c5c7635550966e665334 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 6 May 2016 19:39:00 +0800 Subject: [PATCH] Avoid auto-deleting empty structure root folders (e.g. Media, Staging, etc) --- .../net/filebot/ui/rename/RenameAction.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/source/net/filebot/ui/rename/RenameAction.java b/source/net/filebot/ui/rename/RenameAction.java index 21153ad1..171dda88 100644 --- a/source/net/filebot/ui/rename/RenameAction.java +++ b/source/net/filebot/ui/rename/RenameAction.java @@ -164,23 +164,22 @@ class RenameAction extends AbstractAction { return; } - // guess affected folder depth - int relativePathSize = 0; try { - relativePathSize = listStructurePathTail(s).size(); + // guess affected folder depth + int tailSize = listStructurePathTail(s).size(); + + for (int i = 0; i < tailSize && !isStructureRoot(sourceFolder); sourceFolder = sourceFolder.getParentFile(), i++) { + File[] children = sourceFolder.listFiles(); + if (children == null || !stream(children).allMatch(f -> empty.contains(f) || f.isHidden())) { + return; + } + + stream(children).forEach(empty::add); + empty.add(sourceFolder); + } } catch (Exception e) { debug.warning(e::toString); } - - for (int i = 0; i < relativePathSize && !isVolumeRoot(sourceFolder); sourceFolder = sourceFolder.getParentFile(), i++) { - File[] children = sourceFolder.listFiles(); - if (children == null || !stream(children).allMatch(f -> empty.contains(f) || f.isHidden())) { - return; - } - - stream(children).forEach(empty::add); - empty.add(sourceFolder); - } }); for (File f : empty) {