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

/**
 * //w w w. j a  va2 s . c o  m
 * @param f
 */
public static void deleteDir(File f) {
    try {
        if (f.isDirectory()) {
            for (File c : f.listFiles()) {
                deleteDir(c);
            }
        }
        f.delete();
    } catch (Exception e) {

    }
}

From source file:Main.java

public static void deleteRecursive(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory()) {
        for (File child : fileOrDirectory.listFiles()) {
            deleteRecursive(child);/*from w  w w .ja v  a2s. co  m*/
        }
    }

    fileOrDirectory.delete();
}

From source file:appStructure.MainApp.java

/**
 * //from   w ww  .jav a 2 s.co m
 * @param questionnaires
 */
private static void creerQuestionaires(Map<String, Module> questionnaires) {

    File folder = new File("./Ressources");
    File[] listOfFiles = folder.listFiles();
    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            String fileName = listOfFiles[i].getName().substring(0, listOfFiles[i].getName().lastIndexOf("."));

            questionnaires.put(WordUtils.uncapitalize(fileName), new Module(fileName));

        }
    }

}

From source file:Main.java

public static void removeOldVersionFiles(Context context, String fileName) {
    File dataDirPath = new File(context.getApplicationInfo().dataDir);
    File[] fileList = dataDirPath.listFiles();

    for (File file : fileList) {
        if (file.getAbsoluteFile().toString().endsWith(fileName)) {
            file.delete();/* w  ww . j  a  v  a 2  s  . com*/
        }
    }
}

From source file:Main.java

public static void innerListFiles(Collection<File> files, File directory, FileFilter filter) {
    File[] found = directory.listFiles();
    if (found != null) {
        for (int i = 0; i < found.length; i++) {
            if (found[i].isDirectory()) {
                innerListFiles(files, found[i], filter);
            } else {
                File[] found2 = directory.listFiles((FileFilter) filter);
                for (int j = 0; j < found2.length; j++) {
                    files.add(found2[j]);
                }/*from  w w w.  j av  a  2 s  .c  o  m*/
            }
        }
    }
}

From source file:Main.java

public static final void clearFolder(String path) {
    File tempFolder = new File(path);
    if (tempFolder.exists()) {
        File[] tempFiles = tempFolder.listFiles();
        for (File tempFile : tempFiles) {
            tempFile.delete();// w w w . j  a  v a2  s.  co m
        }
    }
}

From source file:com.asakusafw.runtime.stage.launcher.Util.java

private static List<File> list(File file) {
    return Optional.ofNullable(file.listFiles()).map(Arrays::asList).orElse(Collections.emptyList());
}

From source file:Main.java

public static void deleteDir(File f) {
    if (f.exists() && f.isDirectory()) {
        for (File file : f.listFiles()) {
            if (file.isDirectory())
                deleteDir(file);//from   w  w w .  j  a  v a2  s.c o m
            file.delete();
        }
        f.delete();
    }
}

From source file:Main.java

public static void removeDirectory(File dir) {
    if (dir.isDirectory()) {
        final File[] files = dir.listFiles();
        if (files != null) {
            for (final File file : files) {
                removeDirectory(file);// w  ww  .  ja  v a2 s  .  co  m
            }
        }
        dir.delete();
    } else {
        dir.delete();
    }
}

From source file:Main.java

public static long getFolderSize(File file) {
    long size = 0;
    try {//from   w ww  .j a  va2 s.  c  o m
        java.io.File[] fileList = file.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isDirectory()) {
                size = size + getFolderSize(fileList[i]);
            } else {
                size = size + fileList[i].length();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return size;
}