/** * Return a list of file names in this directory. Hidden files will be * included in the list. * If this is not a directory, return null. */ public String[] list() { return list(false); }
/** * Return a list of relative file names in this directory, or null * if this file is not a directory. * * @return a list of file names in this directory. Hidden files will be * included in the list. If this is not a directory, return null. * @see #list(boolean) */ public String[] list() { return list(false); }
/** * Returns true if this pathname exists and represents a directory. * * @see java.io.File#isDirectory() */ public boolean isDirectory() { LOGGER.trace("isDirectory()"); if (isURL) { String[] list = list(); return list != null; } return file.isDirectory(); }
private String[] getAllFiles(String dir) { ArrayList<String> files = new ArrayList<String>(); Location root = new Location(dir); String[] children = root.list(); for (String child : children) { Location file = new Location(root, child); if (file.isDirectory()) { String[] grandchildren = getAllFiles(file.getAbsolutePath()); for (String g : grandchildren) { files.add(g); } } else { files.add(file.getAbsolutePath()); } } return files.toArray(new String[files.size()]); }
/** * Return a list of absolute files in this directory. Hidden files will * be included in the list. * If this is not a directory, return null. */ public Location[] listFiles() { String[] s = list(); if (s == null) return null; Location[] f = new Location[s.length]; for (int i=0; i<f.length; i++) { f[i] = new Location(getAbsolutePath(), s[i]); f[i] = f[i].getAbsoluteFile(); } return f; }
@Override public int fileGroupOption(String id) throws FormatException, IOException { if (checkSuffix(id, ND_SUFFIX)) return FormatTools.MUST_GROUP; Location l = new Location(id).getAbsoluteFile(); String[] files = l.getParentFile().list(); for (String file : files) { if (checkSuffix(file, ND_SUFFIX) && l.getName().startsWith(file.substring(0, file.lastIndexOf(".")))) { return FormatTools.MUST_GROUP; } } return FormatTools.CANNOT_GROUP; }
@Override public int fileGroupOption(String id) throws FormatException, IOException { if (checkSuffix(id, ND_SUFFIX)) return FormatTools.MUST_GROUP; Location l = new Location(id).getAbsoluteFile(); String[] files = l.getParentFile().list(); for (String file : files) { if (checkSuffix(file, ND_SUFFIX) && l.getName().startsWith(file.substring(0, file.lastIndexOf(".")))) { return FormatTools.MUST_GROUP; } } return FormatTools.CANNOT_GROUP; }
@Override public int fileGroupOption(String id) throws FormatException, IOException { Location thisFile = new Location(id).getAbsoluteFile(); Location parent = thisFile.getParentFile(); String[] list = parent.list(true); for (String f : list) { if (checkSuffix(f, "raw") || checkSuffix(f, "xml")) { return FormatTools.MUST_GROUP; } } return FormatTools.CAN_GROUP; }
/** Finds the first file with one of the given suffixes. */ private Location find(final String[] suffix) { final Location file = new Location(currentId).getAbsoluteFile(); final Location parent = file.getParentFile(); final String[] listing = parent.list(); for (final String name : listing) { if (checkSuffix(name, suffix)) { return new Location(parent, name); } } return null; }
/** Finds the first file with one of the given suffixes. */ private Location find(final String[] suffix) { final Location file = new Location(currentId).getAbsoluteFile(); final Location parent = file.getParentFile(); final String[] listing = parent.list(); for (final String name : listing) { if (checkSuffix(name, suffix)) { return new Location(parent, name); } } return null; }
@Override public int fileGroupOption(String id) throws FormatException, IOException { Location thisFile = new Location(id).getAbsoluteFile(); Location parent = thisFile.getParentFile(); String[] list = parent.list(true); for (String f : list) { if (checkSuffix(f, "raw") || checkSuffix(f, "xml")) { return FormatTools.MUST_GROUP; } } return FormatTools.CAN_GROUP; }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { if (checkSuffix(id, "xml")) return false; Location file = new Location(id); String[] list = file.getParentFile().list(); for (String f : list) { if (checkSuffix(f, "xml") && DataTools.samePrefix(file.getName(), f)) { return false; } } return true; }
/** * Works like {@link #findSeriesPatterns(String, String, String[])}, * but dir and nameList are inferred from the given file's absolute * path. * * @param base The file basename to use as a template for the match. * @return an array containing all identified patterns. */ public static String[] findSeriesPatterns(String base) { Location file = new Location(base).getAbsoluteFile(); Location parent = file.getParentFile(); String[] list = parent.list(true); if (list == null) { list = new String[0]; } return findSeriesPatterns(base, parent.getAbsolutePath(), list); }
/** * Recursively add all of the files in the given directory to the * used file list. */ private void addDirectory(String path, int series) { Location dir = new Location(path); String[] files = dir.list(); if (files == null) return; for (String f : files) { Location file = new Location(path, f); if (file.isDirectory()) { addDirectory(file.getAbsolutePath(), series); } else if (checkSuffix(f, "scn")) { metadataFiles[series].add(file.getAbsolutePath()); } } }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { if (checkSuffix(id, "xml")) return false; Location file = new Location(id); String[] list = file.getParentFile().list(); for (String f : list) { if (checkSuffix(f, "xml") && DataTools.samePrefix(file.getName(), f)) { return false; } } return true; }
/** * Works like {@link #findSeriesPatterns(String, String, String[])}, * but dir and nameList are inferred from the given file's absolute * path. * * @param base The file basename to use as a template for the match. * @return an array containing all identified patterns. */ public static String[] findSeriesPatterns(String base) { Location file = new Location(base).getAbsoluteFile(); Location parent = file.getParentFile(); String[] list = parent.list(true); if (list == null) { list = new String[0]; } return findSeriesPatterns(base, parent.getAbsolutePath(), list); }
/** * Recursively add all of the files in the given directory to the * used file list. */ private void addDirectory(String path, int series) { Location dir = new Location(path); String[] files = dir.list(); if (files == null) return; for (String f : files) { Location file = new Location(path, f); if (file.isDirectory()) { addDirectory(file.getAbsolutePath(), series); } else if (checkSuffix(f, "scn")) { metadataFiles[series].add(file.getAbsolutePath()); } } }
public static void parseConfigFiles(String dir, ConfigurationTree config) { Location root = new Location(dir); String[] files = root.list(); for (String file : files) { Location check = new Location(root, file); if (check.isDirectory()) { parseConfigFiles(check.getAbsolutePath(), config); } else if (isConfigFile(check, "")) { try { config.parseConfigFile(check.getAbsolutePath()); } catch (IOException e) { LOGGER.warn("Failed to parse config {}", check, e); } } } }
@Override protected void initFile(String id) throws FormatException, IOException { if (!checkSuffix(id, "tif")) { Location parent = new Location(id).getAbsoluteFile().getParentFile(); String[] list = parent.list(true); for (String f : list) { if (checkSuffix(f, "tif")) { String path = new Location(parent, f).getAbsolutePath(); if (isThisType(path)) { id = path; break; } } } } super.initFile(id); }
@Override protected void initFile(String id) throws FormatException, IOException { if (!checkSuffix(id, "tif")) { Location parent = new Location(id).getAbsoluteFile().getParentFile(); String[] list = parent.list(true); for (String f : list) { if (checkSuffix(f, "tif")) { String path = new Location(parent, f).getAbsolutePath(); if (isThisType(path)) { id = path; break; } } } } super.initFile(id); }