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

public static void deleteDirContent(File dir) {
    final File[] files = dir.listFiles();
    if (files != null) {
        for (final File file : files) {
            if (file.isDirectory()) {
                deleteDirContent(file);/*from w w  w .  j ava 2  s.com*/
            }
            file.delete();
        }
    }
}

From source file:Main.java

public static void File_iterateFiles(String dir) {
    File f = new File(dir);
    File[] files = f.listFiles();
    if (null != files) {
        for (File ff : files) {
            if (ff.isDirectory()) {
                File_iterateFiles(ff.getPath());
            } else {
                //TODO
            }//from w  w w  .ja  v  a2s .co m
        }
    }
}

From source file:Main.java

public static void deleteFiles(String path, String excludeSuffix) {
    File dir = new File(path);
    File[] files = dir.listFiles();
    if (files != null && files.length > 0) {
        for (File file : files) {
            if (excludeSuffix != null && file.getName().contains(excludeSuffix)) {
                continue;
            }/*  ww w  . j a  va2 s .  c om*/
            file.delete();
        }
    }
}

From source file:Main.java

private static void deleteDir(File dir) {
    File[] files = dir.listFiles();
    if (files != null & files.length > 0) {
        for (File file : files) {
            if (file.isFile()) {
                file.delete();//from   w ww  .j av a  2s  .c  o  m
            } else if (file.isDirectory()) {
                deleteDir(file);
            }
        }
    }
    dir.delete();
}

From source file:Main.java

public static long doCalcularTamanhoDiretorio(File dir) {
    long tamanho = 0;
    for (File f : dir.listFiles()) {
        tamanho += f.length();/*from  w w w.  j  av  a  2 s .c  o  m*/
    }

    return tamanho;
}

From source file:Main.java

public static File[] getXMLFiles(File folder) {
    List<File> aList = new ArrayList<File>();

    File[] files = folder.listFiles();
    for (File pf : files) {

        if (pf.isFile() && getFileExtensionName(pf).indexOf("xml") != -1) {
            aList.add(pf);//w w  w  . j  av  a 2s. c  o  m
        }
    }
    return aList.toArray(new File[aList.size()]);
}

From source file:Main.java

/**
 * Recursively deletes folder and files.
 * /*from  w  w  w  . ja v  a  2s .  c  o m*/
 * @param folder
 */
private static void delete(File folder) {
    File[] files = folder.listFiles();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        if (file.isDirectory()) {
            delete(file);
        }
        file.delete();
    }
    folder.delete();
}

From source file:Main.java

/**
 * Deletes the directory passed as parameters
 * @param dir//w ww. jav  a  2 s . c  o m
 *       the directory to delete
 */
public static void deleteDir(File dir) {
    File[] list = dir.listFiles();
    for (int i = 0; i < list.length; i++) {
        if (list[i].isDirectory())
            deleteDir(list[i]);
        else
            list[i].delete();
    }
    dir.delete();
}

From source file:Main.java

static private List<File> getFiles(String src) {
    List<File> list = new ArrayList<File>();
    File f = new File(src);
    File files[] = f.listFiles();
    for (File file : files) {
        if (file.isFile()) {
            list.add(file);/*from w ww.  j  ava 2 s .c o  m*/
        } else {
            list.addAll(getFiles(file.getPath()));
        }
    }
    return list;
}

From source file:Main.java

/**
 * Recursively list all files within a directory and sub directories
 * @param f File to search//from  w  ww . jav a 2 s.c o m
 * @param files List of files found
 */
public static void listFiles(File f, ArrayList<File> files) {
    File[] fs = f.listFiles();
    for (File file : fs) {
        if (file.isFile() && file.getPath().endsWith(".jar")) {
            files.add(file);
        } else if (file.isDirectory()) {
            listFiles(file, files);
        }
    }
}