Example usage for java.io File list

List of usage examples for java.io File list

Introduction

In this page you can find the example usage for java.io File list.

Prototype

public String[] list(FilenameFilter filter) 

Source Link

Document

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Usage

From source file:com.hurence.logisland.documentation.DocGenerator.java

/**
 * Checks to see if a directory to write to has an additionalDetails.html in
 * it already./*w  ww  .j a va2s  .  c  o m*/
 *
 * @param directory to check
 * @return true if additionalDetails.html exists, false otherwise.
 */
private static boolean hasAdditionalInfo(File directory) {
    return directory.list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.equalsIgnoreCase(HtmlDocumentationWriter.ADDITIONAL_DETAILS_HTML);
        }

    }).length > 0;
}

From source file:com.twinsoft.convertigo.engine.util.ZipUtils.java

private static int putEntries(ZipOutputStream zos, String sDir, String sRelativeDir,
        final List<File> excludedFiles) throws Exception {
    Engine.logEngine.trace("==========================================================");
    Engine.logEngine.trace("sDir=" + sDir);
    Engine.logEngine.trace("sRelativeDir=" + sRelativeDir);
    Engine.logEngine.trace("excludedFiles=" + excludedFiles);

    File dir = new File(sDir);
    String[] files = dir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            File file = new File(dir, name);
            return (!excludedFiles.contains(file));
        }/*w ww  .j  a v  a2s . c  om*/
    });

    Engine.logEngine.trace("files=" + files);

    int nbe = 0;
    for (String file : files) {
        String sDirEntry = sDir + "/" + file;
        String sRelativeDirEntry = sRelativeDir != null ? (sRelativeDir + "/" + file) : file;

        File f = new File(sDirEntry);
        if (!f.isDirectory()) {
            Engine.logEngine.trace("+ " + sDirEntry);
            InputStream fi = new FileInputStream(f);

            try {
                ZipEntry entry = new ZipEntry(sRelativeDirEntry);
                entry.setTime(f.lastModified());
                zos.putNextEntry(entry);
                IOUtils.copy(fi, zos);
                nbe++;
            } finally {
                fi.close();
            }
        } else {
            nbe += putEntries(zos, sDirEntry, sRelativeDirEntry, excludedFiles);
        }
    }
    return nbe;
}

From source file:com.freemedforms.openreact.db.DbSchema.java

public static void dbPatcher(String patchLocation) {
    log.info("Database patching started for " + patchLocation);

    File patchDirectoryObject = new File(patchLocation);
    String[] children = patchDirectoryObject.list(new FilenameFilter() {
        @Override//from   w  w w .ja  v  a2 s .c o m
        public boolean accept(File file, String name) {
            log.debug("file = " + file + ", name = " + name);
            if (name.startsWith(".")) {
                log.debug("Skipping " + name + " (dot file)");
                return false;
            }
            if (!name.endsWith(".sql")) {
                log.debug("Skipping " + name + " (doesn't end with .sql)");
                return false;
            }
            return true;
        }
    });
    if (children != null) {
        // Sort all patches into name order.
        Arrays.sort(children);

        // Process patches
        log.info("Found " + children.length + " patches to process");
        for (String patchFilename : children) {
            String patchName = FilenameUtils.getBaseName(patchFilename);
            if (DbSchema.isPatchApplied(patchName)) {
                log.info("Patch " + patchName + " already applied.");
                continue;
            } else {
                log.info("Applying patch " + patchName + ", source file = " + patchFilename);
                boolean success;
                try {
                    success = DbSchema.applyPatch(
                            patchDirectoryObject.getAbsolutePath() + File.separatorChar + patchFilename);
                } catch (SQLException e) {
                    log.error(e);
                    success = false;
                }
                if (success) {
                    DbSchema.recordPatch(patchName);
                } else {
                    log.error("Failed to apply " + patchName + ", stopping patch sequence.");
                    return;
                }
            }
        }
    }
    log.info("Database patching completed");
}

From source file:com.yattatech.util.SeminaryUtil.java

public static boolean hasSeminaries() {
    final File file = new File(PATH);
    String[] files = null;//w w  w. ja v a  2s .  c  om
    if (file.exists()) {
        LOGGER.info(String.format("checking seminaries in %s", PATH));
        files = file.list(FILTER);
    } else {
        LOGGER.info("has no seminaries files created");
    }
    return ((files != null) && (files.length > 0));
}

From source file:de.blizzy.backup.Utils.java

public static int getMaxBackupFileIndex(File folder) {
    if (folder.isDirectory()) {
        List<String> files = Arrays.asList(folder.list(new FilenameFilter() {
            @Override// w w w .j a  va2 s  .c om
            public boolean accept(File dir, String name) {
                return name.indexOf('-') < 0;
            }
        }));
        if (!files.isEmpty()) {
            Collections.sort(files, new Comparator<String>() {
                @Override
                public int compare(String f1, String f2) {
                    int idx1 = toBackupFileIndex(f1);
                    int idx2 = toBackupFileIndex(f2);
                    if (idx1 < idx2) {
                        return -1;
                    }
                    if (idx1 > idx2) {
                        return 1;
                    }
                    return 0;
                }
            });
            return toBackupFileIndex(files.get(files.size() - 1));
        }
    }
    return 0;
}

From source file:fr.inria.eventcloud.deployment.cli.launchers.EventCloudsManagementServiceDeployer.java

private static String addClassPath(String libsUrl) throws IOException {
    downloadLibs(libsUrl);/*from www  .  ja v a 2  s.co m*/

    File libDir = new File(libDirPath);
    String[] libNames = libDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });

    StringBuilder classPath = new StringBuilder();
    for (String libName : libNames) {
        classPath.append(libDirPath).append(File.separator).append(libName).append(File.pathSeparator);
    }
    classPath.delete(classPath.length() - 2, classPath.length() - 1);

    return classPath.toString();
}

From source file:it.cnr.isti.thematrix.mapping.utils.TempFileManager.java

/**
 * Return the path of a file. //  www  .  j  a v  a2  s.  c o m
 * First checks presence in IAD directory, if not return results as path for the file.
 * It expects a file in the format of filename.extension.
 * @param filename
 * @return the path of a file
 */
// FIXME: this method should be moved elsewhere
public static File getPathForFile(String filename) {
    File iad = new File(Dynamic.getIadPath());
    File result = new File(Dynamic.getResultsPath());

    String[] iad_list = iad.list(new NameFileFilter(filename));
    String[] result_list = result.list(new NameFileFilter(filename));

    if (iad_list.length > 0 && result_list.length > 0)
        LogST.logP(0, "*** WARNING: found the file " + filename
                + " both in IAD and RESULTs. Now reading from RESULTS.");

    if (result_list.length > 0)
        return result;
    else if (iad_list.length > 0)
        return iad;
    else
        return result;
}

From source file:core.Utility.java

public static boolean hasTextFiles(File file) {
    if (file.isDirectory()) {
        String[] files = file.list(new FilenameFilter() {

            @Override//from w  w  w .  j ava 2 s  . co  m
            public boolean accept(File dir, String name) {
                return (name.toLowerCase().endsWith(".txt"));
            }
        });

        return (files.length > 0);
    }
    return true;
}

From source file:fr.eo.util.dumper.Dumper.java

private static int getDumpLinesNumber() {
    File assertDir = new File(assetFolder);

    String[] dumpFileNames = assertDir.list(new FilenameFilter() {

        @Override//from   ww  w . java  2s .c  o  m
        public boolean accept(File dir, String name) {
            return name.startsWith("dump") && name.endsWith(".sql");
        }
    });

    int nbDumpLines = 0;

    BufferedReader reader = null;
    try {
        for (String name : dumpFileNames) {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(assetFolder + name)));
            String currentLine = null;
            while ((currentLine = reader.readLine()) != null) {
                currentLine = currentLine.trim();
                if (currentLine.length() != 0 && !currentLine.startsWith("--")) {
                    nbDumpLines++;
                }
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return nbDumpLines;
}

From source file:gobblin.aws.GobblinAWSUtils.java

private static String getClasspathFromPath(File path) {
    if (null == path) {
        return StringUtils.EMPTY;
    }/*from   w  w  w.  j a v  a 2 s  .c  om*/
    if (!path.isDirectory()) {
        return path.getAbsolutePath();
    }

    return Joiner.on(":").skipNulls().join(path.list(FileFileFilter.FILE));
}