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 clearTemp(Activity activity) {
    File folder = new File(activity.getExternalFilesDir(null), "temp");
    if (null != folder.listFiles()) {
        for (File file : folder.listFiles()) {
            file.delete();//  ww  w .  j a v  a 2s . com
        }
    }
}

From source file:com.fluke.application.IEODReader.java

static void processFolder(List<File> folders) throws IOException {
    List<File> newFolders = new ArrayList<>();
    for (File file : folders) {
        processChildren(file.listFiles(), newFolders);
    }/*from  ww w  .j ava  2 s .c  o  m*/
    if (!newFolders.isEmpty()) {
        processFolder(newFolders);
    }
}

From source file:Main.java

public static void deleteDir(File file) {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            deleteDir(f);/*from  w w  w  .j a v a 2 s.co  m*/
        }
    }

    file.delete();
}

From source file:Main.java

public static void delete(final File dir) {
    if (dir.isDirectory()) {
        final File[] files = dir.listFiles();
        if (null != files && files.length > 0) {
            for (final File file : files) {
                delete(file);/*from  w  ww  .ja  v a  2  s  .c  om*/
            }
        }
    }
    dir.delete();
}

From source file:Main.java

public static void deleteNonFolders(File paramFile) {
    if (paramFile.isDirectory()) {
        File[] arrayOfFile = paramFile.listFiles();
        int i = arrayOfFile.length;
        for (int j = 0; j < i; j++)
            deleteNonFolders(arrayOfFile[j]);
    }// w  ww.  j a  va 2s . c o m
}

From source file:Main.java

/**
 * Delete a directory and its content./*from w  ww  .j a  v a  2s  .  c o  m*/
 * 
 * @param path
 *            The directory to delete.
 */
static public void deleteDirectory(File path) {
    if (path.exists()) {
        File[] files = path.listFiles();
        if (files == null) {
            return;
        }
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                deleteDirectory(files[i]);
            } else {
                files[i].delete();
            }
        }
    }
    path.delete();
}

From source file:Main.java

public static String[] getFicherosDirectorio(String directorio_carga) {
    File directorio = getFileDirectorio(directorio_carga);
    File ficheros[] = directorio.listFiles();
    String[] lista = new String[ficheros.length];
    for (int i = 0; i < ficheros.length; i++) {
        lista[i] = ficheros[i].getPath();
    }//w  w  w  .  j a v  a2  s .c  o m
    return lista;
}

From source file:Main.java

private static void deleteDirectory(String cachePath) {
    File file = new File(cachePath);
    if (file.exists()) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            files[i].delete();//from w ww  .  jav  a2s . c  o  m
        }
    }
}

From source file:Main.java

private static void removeDirectory(File directory) {
    if (directory.isDirectory()) {
        File[] files = directory.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                removeDirectory(files[i]);
            }/*from   w w w .  j ava  2s  .  co  m*/
            files[i].delete();
        }
        directory.delete();
    }
}

From source file:Main.java

private static boolean containsTestData(File dir, Pattern filenamePattern) {
    File[] files = dir.listFiles();
    assert files != null;
    for (File file : files) {
        if (file.isDirectory()) {
            if (containsTestData(file, filenamePattern)) {
                return true;
            }// ww w .  j  a va  2 s  .  co m
        } else {
            if (filenamePattern.matcher(file.getName()).matches()) {
                return true;
            }
        }
    }
    return false;
}