Example usage for java.io File listFiles

List of usage examples for java.io File listFiles

Introduction

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

Prototype

public File[] listFiles() 

Source Link

Document

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

Usage

From source file:Main.java

@SuppressWarnings("WeakerAccess")
public static boolean cleanDir(File dir) {
    if (dir == null || !dir.exists() || !dir.isDirectory()) {
        return true;
    }//w ww. j a v  a2 s .  c  o  m

    File[] files = dir.listFiles();
    boolean cleanSuccess = true;
    if (files != null) {
        for (File tempFile : files) {
            if (tempFile.isDirectory()) {
                cleanSuccess &= cleanDir(tempFile);
            }
            cleanSuccess &= tempFile.delete();
        }
    }
    return cleanSuccess;
}

From source file:com.github.megatronking.svg.cli.Main.java

private static void svg2vectorForDirectory(File inputDir, File outputDir, int width, int height) {
    File[] childFiles = inputDir.listFiles();
    if (childFiles != null) {
        for (File childFile : childFiles) {
            if (childFile.isFile() && childFile.length() > 0) {
                svg2vectorForFile(childFile,
                        new File(outputDir, FileUtils.noExtensionLastName(childFile) + ".xml"), width, height);
            }/*from   ww w  .ja  va2s.co  m*/
        }
    }
}

From source file:com.predic8.membrane.examples.config.ConfigSerializationTest.java

private static void recurse(File file, ArrayList<Object[]> res) {
    OUTER: for (File f : file.listFiles()) {
        if (f.isDirectory())
            recurse(f, res);//from ww  w  .j av  a  2  s .com
        if (f.isFile() && f.getName().equals("proxies.xml")) {
            String path = f.getAbsolutePath();
            for (String exclude : EXCLUDED)
                if (path.contains(File.separator + exclude + File.separator))
                    continue OUTER;
            res.add(new Object[] { path });
        }
    }
}

From source file:name.martingeisse.esdk.simulation.lwjgl.NativeLibraryHelper.java

/**
 * //  w ww.ja  v a2 s  .  co  m
 */
private static void deleteRecursively(File file) throws IOException {
    if (file.isDirectory()) {
        for (File sub : file.listFiles()) {
            deleteRecursively(sub);
        }
    }
    file.delete();
}

From source file:Main.java

public static List<String> getFolderContent(String folderDir) {
    File file = new File(folderDir);
    List<String> filesPath = new ArrayList<>();
    if (!file.exists()) {

    } else {/* w w  w .j  av a  2 s.  co  m*/
        for (File f : file.listFiles()) {
            if (f.isFile()) {
                filesPath.add(f.getPath());
            }
        }
    }
    return filesPath;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.createdebate.CorpusPreparator.java

/**
 * Extracts all debates from raw HTML files in inFolder and stores them into outFolder
 * as serialized {@link Debate} objects (see {@link DebateSerializer}.
 *
 * @param inFolder     in folder/*  w  w  w .  ja  v  a2s . c om*/
 * @param outFolder    out folder (must exist)
 * @param debateParser debate parser implementation
 * @throws IOException exception
 */
public static void extractAllDebates(File inFolder, File outFolder, DebateParser debateParser)
        throws IOException {
    File[] files = inFolder.listFiles();
    if (files == null) {
        throw new IOException("No such dir: " + inFolder);
    }

    for (File f : files) {
        InputStream inputStream = new FileInputStream(f);
        try {
            Debate debate = debateParser.parseDebate(inputStream);

            // we ignore empty debates (without arguments)
            if (debate != null && !debate.getArgumentList().isEmpty()) {
                // serialize to xml
                String xml = DebateSerializer.serializeToXML(debate);

                // same name with .xml
                File outputFile = new File(outFolder, f.getName() + ".xml");

                FileUtils.writeStringToFile(outputFile, xml, "utf-8");
                System.out.println("Saved to " + outputFile.getAbsolutePath());

                // ensure we can read it again
                DebateSerializer.deserializeFromXML(FileUtils.readFileToString(outputFile));
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }

}

From source file:edu.columbia.sel.grout.util.TileUtils.java

/**
 * Recursively delete a directory and its contents. Returns true on succes, false otherwise.
 * @param dir//from ww  w.j  av  a2  s . co  m
 * @return boolean
 */
public static boolean deleteDirectory(File dir) {
    if (dir.exists()) {
        File[] files = dir.listFiles();
        if (files == null) {
            return true;
        }
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                deleteDirectory(files[i]);
            } else {
                files[i].delete();
            }
        }
    }
    return (dir.delete());
}

From source file:Main.java

public static boolean isNoMediaDir(File dir) {
    boolean result = false;
    if (dir == null || dir.isFile()) {
        result = true;//from  ww w.  j  ava 2 s . com
    } else {
        File[] files = dir.listFiles();
        if (files != null) {
            for (File childFile : files) {
                if (childFile.isFile() && ".nomedia".equals(childFile.getName())) {
                    result = true;
                    break;
                }
            }
        }
    }
    return result;
}

From source file:com.yata.core.FileManager.java

public static void deleteDirectoryContent(String filePath) {

    System.out.println("deleteFile@" + className + " : File to Delete :-> " + filePath);

    File file = new File(filePath);

    for (File childFile : file.listFiles()) {

        FileUtils.deleteQuietly(childFile);
    }/*  www.j  a va2s . c  o  m*/
}

From source file:edu.clemson.cs.nestbed.server.util.FileUtils.java

public static void deleteDirectory(File directory) {
    if (directory.isDirectory()) {
        File[] files = directory.listFiles();

        for (int i = 0; i < files.length; ++i) {
            if (files[i].isDirectory()) {
                deleteDirectory(files[i]);
            } else {
                files[i].delete();// w  w w.java  2 s  . co  m
            }
        }

        directory.delete();
    }
}