Use human sort order for all paths loaded into the UI
This commit is contained in:
parent
aea553b154
commit
846e4166ed
|
@ -160,9 +160,9 @@ public class ArgumentBean {
|
||||||
|
|
||||||
if (resolveFolders && file.isDirectory()) {
|
if (resolveFolders && file.isDirectory()) {
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
files.addAll(listFiles(file));
|
files.addAll(listFiles(file, FILES));
|
||||||
} else {
|
} else {
|
||||||
files.addAll(filter(getChildren(file, FILES), NOT_HIDDEN));
|
files.addAll(getChildren(file, FILES));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
files.add(file);
|
files.add(file);
|
||||||
|
|
|
@ -145,7 +145,7 @@ public abstract class FolderWatchService implements Closeable {
|
||||||
// start watching newly created folder
|
// start watching newly created folder
|
||||||
if (watchTree) {
|
if (watchTree) {
|
||||||
try {
|
try {
|
||||||
commitSet.addAll(listFiles(file));
|
commitSet.addAll(listFiles(file, FILES));
|
||||||
watchFolder(file);
|
watchFolder(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
debug.log(Level.SEVERE, e.getMessage(), e);
|
debug.log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.media.XattrMetaInfo.*;
|
import static net.filebot.media.XattrMetaInfo.*;
|
||||||
|
import static net.filebot.util.FileUtilities.*;
|
||||||
import static net.filebot.util.StringUtilities.*;
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -46,7 +47,6 @@ import net.filebot.WebServices;
|
||||||
import net.filebot.format.AssociativeScriptObject;
|
import net.filebot.format.AssociativeScriptObject;
|
||||||
import net.filebot.media.MediaDetection;
|
import net.filebot.media.MediaDetection;
|
||||||
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
||||||
import net.filebot.util.FileUtilities;
|
|
||||||
import net.filebot.web.Movie;
|
import net.filebot.web.Movie;
|
||||||
|
|
||||||
public abstract class ScriptShellBaseClass extends Script {
|
public abstract class ScriptShellBaseClass extends Script {
|
||||||
|
@ -95,7 +95,7 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object executeScript(String input, Map<String, ?> bindings, Object... args) throws Throwable {
|
public Object executeScript(String input, Map<String, ?> bindings, Object... args) throws Throwable {
|
||||||
return executeScript(input, asList(getArgumentBean().getArray()), bindings, FileUtilities.asFileList(args));
|
return executeScript(input, asList(getArgumentBean().getArray()), bindings, asFileList(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object executeScript(String input, List<String> argv, Map<String, ?> bindings, List<File> args) throws Throwable {
|
public Object executeScript(String input, List<String> argv, Map<String, ?> bindings, List<File> args) throws Throwable {
|
||||||
|
@ -212,7 +212,7 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String detectSeriesName(Object files, boolean anime) throws Exception {
|
public String detectSeriesName(Object files, boolean anime) throws Exception {
|
||||||
List<File> input = FileUtilities.asFileList(files);
|
List<File> input = asFileList(files);
|
||||||
if (input.isEmpty())
|
if (input.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getMediaInfo(Collection<?> files, String format) throws Exception {
|
public List<String> getMediaInfo(Collection<?> files, String format) throws Exception {
|
||||||
return cli.getMediaInfo(FileUtilities.asFileList(files), format, null); // explicitly ignore the --filter option
|
return cli.getMediaInfo(asFileList(files), format, null); // explicitly ignore the --filter option
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getMediaInfo(Map<String, ?> parameters) throws Exception {
|
public Object getMediaInfo(Map<String, ?> parameters) throws Exception {
|
||||||
|
@ -453,12 +453,12 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
private List<File> getInputFileList(Map<String, ?> parameters) {
|
private List<File> getInputFileList(Map<String, ?> parameters) {
|
||||||
Object file = parameters.get("file");
|
Object file = parameters.get("file");
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
return FileUtilities.asFileList(file);
|
return asFileList(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object folder = parameters.get("folder");
|
Object folder = parameters.get("folder");
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
return FileUtilities.listFiles(FileUtilities.asFileList(folder), 0, false, true, false);
|
return listFiles(asFileList(folder), 0, FILES, HUMAN_ORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return emptyList();
|
return emptyList();
|
||||||
|
@ -469,8 +469,8 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
Map<File, File> files = new LinkedHashMap<File, File>();
|
Map<File, File> files = new LinkedHashMap<File, File>();
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
for (Entry<?, ?> it : map.entrySet()) {
|
for (Entry<?, ?> it : map.entrySet()) {
|
||||||
List<File> key = FileUtilities.asFileList(it.getKey());
|
List<File> key = asFileList(it.getKey());
|
||||||
List<File> value = FileUtilities.asFileList(it.getValue());
|
List<File> value = asFileList(it.getValue());
|
||||||
if (key.size() == 1 && value.size() == 1) {
|
if (key.size() == 1 && value.size() == 1) {
|
||||||
files.put(key.get(0), value.get(0));
|
files.put(key.get(0), value.get(0));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import static java.util.Collections.*;
|
||||||
import static java.util.stream.Collectors.*;
|
import static java.util.stream.Collectors.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
import static net.filebot.MediaTypes.*;
|
||||||
import static net.filebot.media.XattrMetaInfo.*;
|
import static net.filebot.media.XattrMetaInfo.*;
|
||||||
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -117,7 +118,7 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> listTree(File self, int maxDepth) {
|
public static List<File> listTree(File self, int maxDepth) {
|
||||||
return FileUtilities.listFiles(singleton(self), maxDepth, false, true, true);
|
return FileUtilities.listFiles(singleton(self), maxDepth, FILES, HUMAN_ORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getFiles(File self) {
|
public static List<File> getFiles(File self) {
|
||||||
|
@ -125,7 +126,7 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getFiles(File self, Closure<?> closure) {
|
public static List<File> getFiles(File self, Closure<?> closure) {
|
||||||
return getFiles(singletonList(self), closure);
|
return getFiles(singleton(self), closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getFiles(Collection<?> self) {
|
public static List<File> getFiles(Collection<?> self) {
|
||||||
|
@ -133,14 +134,14 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getFiles(Collection<?> self, Closure<?> closure) {
|
public static List<File> getFiles(Collection<?> self, Closure<?> closure) {
|
||||||
final List<File> roots = FileUtilities.asFileList(self.toArray());
|
List<File> roots = FileUtilities.asFileList(self.toArray());
|
||||||
|
|
||||||
List<File> files = FileUtilities.listFiles(roots);
|
List<File> files = FileUtilities.listFiles(roots, FILES, HUMAN_ORDER);
|
||||||
if (closure != null) {
|
if (closure != null) {
|
||||||
files = DefaultGroovyMethods.findAll(files, closure);
|
files = DefaultGroovyMethods.findAll(files, closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileUtilities.sortByUniquePath(files);
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getFolders(File self) {
|
public static List<File> getFolders(File self) {
|
||||||
|
@ -156,14 +157,14 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getFolders(Collection<?> self, Closure<?> closure) {
|
public static List<File> getFolders(Collection<?> self, Closure<?> closure) {
|
||||||
final List<File> roots = FileUtilities.asFileList(self.toArray());
|
List<File> roots = FileUtilities.asFileList(self.toArray());
|
||||||
|
|
||||||
List<File> folders = FileUtilities.listFolders(roots);
|
List<File> folders = FileUtilities.listFolders(roots, HUMAN_ORDER);
|
||||||
if (closure != null) {
|
if (closure != null) {
|
||||||
folders = DefaultGroovyMethods.findAll(folders, closure);
|
folders = DefaultGroovyMethods.findAll(folders, closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileUtilities.sortByUniquePath(folders);
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> getMediaFolders(File self) throws IOException {
|
public static List<File> getMediaFolders(File self) throws IOException {
|
||||||
|
|
|
@ -34,8 +34,6 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.cedarsoftware.util.io.JsonWriter;
|
import com.cedarsoftware.util.io.JsonWriter;
|
||||||
|
@ -992,9 +990,9 @@ public class MediaBindingBean {
|
||||||
public File getInferredMediaFile() {
|
public File getInferredMediaFile() {
|
||||||
if (getMediaFile().isDirectory()) {
|
if (getMediaFile().isDirectory()) {
|
||||||
// just select the first video file in the folder as media sample
|
// just select the first video file in the folder as media sample
|
||||||
SortedSet<File> videos = new TreeSet<File>(filter(listFiles(getMediaFile()), VIDEO_FILES));
|
List<File> videos = listFiles(getMediaFile(), VIDEO_FILES, CASE_INSENSITIVE_ORDER);
|
||||||
if (videos.size() > 0) {
|
if (videos.size() > 0) {
|
||||||
return videos.iterator().next();
|
return videos.get(0);
|
||||||
}
|
}
|
||||||
} else if (SUBTITLE_FILES.accept(getMediaFile()) || ((infoObject instanceof Episode || infoObject instanceof Movie) && !VIDEO_FILES.accept(getMediaFile()))) {
|
} else if (SUBTITLE_FILES.accept(getMediaFile()) || ((infoObject instanceof Episode || infoObject instanceof Movie) && !VIDEO_FILES.accept(getMediaFile()))) {
|
||||||
// prefer equal match from current context if possible
|
// prefer equal match from current context if possible
|
||||||
|
|
|
@ -1204,7 +1204,7 @@ public class MediaDetection {
|
||||||
Set<Integer> collection = new LinkedHashSet<Integer>();
|
Set<Integer> collection = new LinkedHashSet<Integer>();
|
||||||
List<File> nfoFiles = new ArrayList<File>();
|
List<File> nfoFiles = new ArrayList<File>();
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
nfoFiles.addAll(filter(listFiles(file), NFO_FILES));
|
nfoFiles.addAll(listFiles(file, NFO_FILES));
|
||||||
} else if (file.getParentFile() != null && file.getParentFile().isDirectory()) {
|
} else if (file.getParentFile() != null && file.getParentFile().isDirectory()) {
|
||||||
nfoFiles.addAll(getChildren(file.getParentFile(), NFO_FILES));
|
nfoFiles.addAll(getChildren(file.getParentFile(), NFO_FILES));
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,7 @@ class AttributeTool extends Tool<TableModel> {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = filter(listFiles(root), VIDEO_FILES, SUBTITLE_FILES);
|
List<File> files = listFiles(root, filter(VIDEO_FILES, SUBTITLE_FILES), HUMAN_ORDER);
|
||||||
files.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
Object metaObject = xattr.getMetaInfo(file);
|
Object metaObject = xattr.getMetaInfo(file);
|
||||||
|
|
|
@ -82,9 +82,7 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore non-archives files and trailing multi-volume parts
|
// ignore non-archives files and trailing multi-volume parts
|
||||||
List<File> files = filter(listFiles(root), Archive.VOLUME_ONE_FILTER);
|
List<File> files = listFiles(root, Archive.VOLUME_ONE_FILTER, HUMAN_ORDER);
|
||||||
files.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
|
List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -58,9 +58,7 @@ class MediaInfoTool extends Tool<TableModel> {
|
||||||
return new MediaInfoTableModel();
|
return new MediaInfoTableModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = filter(listFiles(root), VIDEO_FILES, AUDIO_FILES);
|
List<File> files = listFiles(root, filter(VIDEO_FILES, AUDIO_FILES), HUMAN_ORDER);
|
||||||
files.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
Map<MediaInfoKey, String[]> data = new TreeMap<MediaInfoKey, String[]>();
|
Map<MediaInfoKey, String[]> data = new TreeMap<MediaInfoKey, String[]>();
|
||||||
|
|
||||||
try (MediaInfo mi = new MediaInfo()) {
|
try (MediaInfo mi = new MediaInfo()) {
|
||||||
|
|
|
@ -76,8 +76,7 @@ class SplitTool extends Tool<TreeModel> {
|
||||||
int nextPart = 1;
|
int nextPart = 1;
|
||||||
long splitSize = getSplitSize();
|
long splitSize = getSplitSize();
|
||||||
|
|
||||||
List<File> files = listFiles(root);
|
List<File> files = listFiles(root, FILES, HUMAN_ORDER);
|
||||||
files.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
List<TreeNode> rootGroup = new ArrayList<TreeNode>();
|
List<TreeNode> rootGroup = new ArrayList<TreeNode>();
|
||||||
List<File> currentPart = new ArrayList<File>();
|
List<File> currentPart = new ArrayList<File>();
|
||||||
|
|
|
@ -101,7 +101,7 @@ abstract class Tool<M> extends JComponent {
|
||||||
long totalSize = 0;
|
long totalSize = 0;
|
||||||
|
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
totalCount += FileUtilities.listFiles(f).size();
|
totalCount += FileUtilities.listFiles(f, FileUtilities.FILES).size();
|
||||||
totalSize += FileUtils.sizeOf(f);
|
totalSize += FileUtils.sizeOf(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,11 @@ class TypeTool extends Tool<TreeModel> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TreeModel createModelInBackground(File root) throws InterruptedException {
|
protected TreeModel createModelInBackground(File root) throws InterruptedException {
|
||||||
List<File> filesAndFolders = (root != null) ? listFiles(singleton(root), FILE_WALK_MAX_DEPTH, true, true, true) : new ArrayList<File>();
|
if (root == null) {
|
||||||
|
return new DefaultTreeModel(new FolderNode("Types", emptyList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<File> filesAndFolders = listFiles(root, f -> true, HUMAN_ORDER);
|
||||||
List<TreeNode> groups = new ArrayList<TreeNode>();
|
List<TreeNode> groups = new ArrayList<TreeNode>();
|
||||||
|
|
||||||
for (Entry<String, FileFilter> it : getMetaTypes().entrySet()) {
|
for (Entry<String, FileFilter> it : getMetaTypes().entrySet()) {
|
||||||
|
|
|
@ -82,12 +82,9 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
|
||||||
title.accept(getFolderName(files.get(0)));
|
title.accept(getFolderName(files.get(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> list = listFiles(files);
|
|
||||||
list.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
// load all files from the given folders recursively up do a depth of 32
|
// load all files from the given folders recursively up do a depth of 32
|
||||||
format.accept(ListPanel.DEFAULT_FILE_FORMAT);
|
format.accept(ListPanel.DEFAULT_FILE_FORMAT);
|
||||||
model.accept(list);
|
model.accept(listFiles(files, FILES, HUMAN_ORDER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
||||||
loadTorrentFiles(files, values);
|
loadTorrentFiles(files, values);
|
||||||
} else {
|
} else {
|
||||||
// load all files from the given folders recursively up do a depth of 32
|
// load all files from the given folders recursively up do a depth of 32
|
||||||
listFiles(files).stream().sorted(HUMAN_ORDER).map(FastFile::new).forEach(values::add);
|
listFiles(files, FILES, HUMAN_ORDER).stream().map(FastFile::new).forEach(values::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
model.addAll(values);
|
model.addAll(values);
|
||||||
|
|
|
@ -84,13 +84,7 @@ public class Preset {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = listFiles(getInputFolder());
|
return listFiles(getInputFolder(), f -> f.isFile() && filter.accept(f), HUMAN_ORDER);
|
||||||
if (filter != null) {
|
|
||||||
files = filter(files, filter);
|
|
||||||
}
|
|
||||||
files.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
return files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoCompleteMatcher getAutoCompleteMatcher() {
|
public AutoCompleteMatcher getAutoCompleteMatcher() {
|
||||||
|
|
|
@ -19,13 +19,11 @@ import java.awt.dnd.DropTargetEvent;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@ -162,7 +160,7 @@ abstract class SubtitleDropTarget extends JButton {
|
||||||
@Override
|
@Override
|
||||||
protected DropAction getDropAction(List<File> selection) {
|
protected DropAction getDropAction(List<File> selection) {
|
||||||
// accept video files and folders
|
// accept video files and folders
|
||||||
return filter(input, VIDEO_FILES, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel;
|
return filter(selection, VIDEO_FILES, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -177,8 +175,7 @@ abstract class SubtitleDropTarget extends JButton {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = filter(listFiles(selection), VIDEO_FILES);
|
List<File> files = listFiles(selection, VIDEO_FILES, HUMAN_ORDER);
|
||||||
files.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
if (files.size() > 0) {
|
if (files.size() > 0) {
|
||||||
handleDownload(files);
|
handleDownload(files);
|
||||||
|
@ -252,13 +249,10 @@ abstract class SubtitleDropTarget extends JButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform a drop action depending on the given files
|
// perform a drop action depending on the given files
|
||||||
List<File> files = listFiles(selection);
|
List<File> files = listFiles(selection, FILES, HUMAN_ORDER);
|
||||||
|
|
||||||
List<File> videos = filter(files, VIDEO_FILES);
|
List<File> videos = filter(files, VIDEO_FILES);
|
||||||
videos.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
List<File> subtitles = filter(files, SUBTITLE_FILES);
|
List<File> subtitles = filter(files, SUBTITLE_FILES);
|
||||||
subtitles.sort(HUMAN_ORDER);
|
|
||||||
|
|
||||||
Map<File, File> uploadPlan = new LinkedHashMap<File, File>();
|
Map<File, File> uploadPlan = new LinkedHashMap<File, File>();
|
||||||
|
|
||||||
|
|
|
@ -390,6 +390,10 @@ public final class FileUtilities {
|
||||||
return f -> !filter.accept(f);
|
return f -> !filter.accept(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FileFilter filter(FileFilter... filters) {
|
||||||
|
return f -> stream(filters).anyMatch(it -> it.accept(f));
|
||||||
|
}
|
||||||
|
|
||||||
public static List<File> listPath(File file) {
|
public static List<File> listPath(File file) {
|
||||||
return listPathTail(file, Integer.MAX_VALUE, false);
|
return listPathTail(file, Integer.MAX_VALUE, false);
|
||||||
}
|
}
|
||||||
|
@ -455,54 +459,50 @@ public final class FileUtilities {
|
||||||
|
|
||||||
public static final int FILE_WALK_MAX_DEPTH = 32;
|
public static final int FILE_WALK_MAX_DEPTH = 32;
|
||||||
|
|
||||||
public static List<File> listFiles(File... folders) {
|
public static List<File> listFiles(File folder, FileFilter filter) {
|
||||||
return listFiles(asList(folders));
|
return listFiles(singleton(folder), FILE_WALK_MAX_DEPTH, filter, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> listFiles(Iterable<File> folders) {
|
public static List<File> listFiles(File folder, FileFilter filter, Comparator<File> order) {
|
||||||
return listFiles(folders, FILE_WALK_MAX_DEPTH, false, true, false);
|
return listFiles(singleton(folder), FILE_WALK_MAX_DEPTH, filter, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> listFolders(Iterable<File> folders) {
|
public static List<File> listFiles(Iterable<File> folders, FileFilter filter, Comparator<File> order) {
|
||||||
return listFiles(folders, FILE_WALK_MAX_DEPTH, false, false, true);
|
return listFiles(folders, FILE_WALK_MAX_DEPTH, filter, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> listFiles(Iterable<File> folders, int maxDepth, boolean addHidden, boolean addFiles, boolean addFolders) {
|
public static List<File> listFolders(Iterable<File> folders, Comparator<File> order) {
|
||||||
List<File> files = new ArrayList<File>();
|
return listFiles(folders, FILE_WALK_MAX_DEPTH, FOLDERS, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<File> listFiles(Iterable<File> folders, int maxDepth, FileFilter filter, Comparator<File> order) {
|
||||||
|
List<File> sink = new ArrayList<File>();
|
||||||
|
|
||||||
// collect files from directory tree
|
|
||||||
for (File it : folders) {
|
for (File it : folders) {
|
||||||
if (!addHidden && it.isHidden()) // ignore hidden files
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (it.isDirectory()) {
|
if (it.isDirectory()) {
|
||||||
if (addFolders) {
|
listFiles(it, sink, 0, maxDepth, filter, order);
|
||||||
files.add(it);
|
|
||||||
}
|
}
|
||||||
listFiles(it, files, 0, maxDepth, addHidden, addFiles, addFolders);
|
|
||||||
} else if (addFiles && it.isFile()) {
|
if (filter.accept(it)) {
|
||||||
files.add(it);
|
sink.add(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return files;
|
return sink;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void listFiles(File folder, List<File> files, int depth, int maxDepth, boolean addHidden, boolean addFiles, boolean addFolders) {
|
private static void listFiles(File folder, List<File> sink, int depth, int maxDepth, FileFilter filter, Comparator<File> order) {
|
||||||
if (depth > maxDepth)
|
if (depth > maxDepth) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (File it : getChildren(folder)) {
|
|
||||||
if (!addHidden && it.isHidden()) // ignore hidden files
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (it.isDirectory()) {
|
|
||||||
if (addFolders) {
|
|
||||||
files.add(it);
|
|
||||||
}
|
}
|
||||||
listFiles(it, files, depth + 1, maxDepth, addHidden, addFiles, addFolders);
|
|
||||||
} else if (addFiles) {
|
for (File it : getChildren(folder, NOT_HIDDEN, order)) {
|
||||||
files.add(it);
|
if (it.isDirectory()) {
|
||||||
|
listFiles(it, sink, depth + 1, maxDepth, filter, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.accept(it)) {
|
||||||
|
sink.add(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue