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:Utils.java

/**
 * Recursively delete a file and all its contents.
 * /*from   w w  w.jav  a2  s .c  o  m*/
 * @param root
 *          the root to delete
 */
public static void recursiveDelete(File root) {
    if (root == null) {
        return;
    }

    if (root.isDirectory()) {
        File[] files = root.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                if (file.isDirectory()) {
                    recursiveDelete(file);
                } else {
                    file.delete();
                }
            }
        }
    }
    root.delete();
}

From source file:com.clustercontrol.plugin.ClassUtils.java

/**
 * ???CLASSPATH??<br/>//from  w  w w.ja v  a2  s.c o m
 * @param directory ?
 * @throws IOException
 */
public static void addDirToClasspath(File directory) throws IOException {
    if (directory.exists()) {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                addURL(file.toURI().toURL());
            }
        }
    }
}

From source file:com.netflix.nicobar.core.utils.__JDKPaths.java

static void processDirectory0(final Set<String> pathSet, final File file) {
    for (File entry : file.listFiles()) {
        if (entry.isDirectory()) {
            processDirectory1(pathSet, entry, file.getPath());
        } else {/*from ww  w. j  a v  a  2  s  .c  o m*/
            final String parent = entry.getParent();
            if (parent != null)
                pathSet.add(parent);
        }
    }
}

From source file:Main.java

/**
 * @param i slot index//from www  . j  a  va  2  s . c  o  m
 * @return valid directory of BMI device root
 * @throws IOException 
 */
private static File getBMIDeviceRoot(int i) throws IOException {
    File root = new File("/sys/devices/platform/omap_bmi_slot.$i/bmi/bmi-$i/bmi-dev-$i/".replace("$i", "" + i));

    if (!root.exists() || root.isFile() || root.listFiles().length == 0)
        return null;

    return root;
}

From source file:Main.java

/**
 * get all the log files to upload/*from   www . ja  v a 2 s .co  m*/
 * 
 * @return
 */
public static File[] getFilesToUpload() {
    File[] files = null;
    File directory = new File(Environment.getExternalStorageDirectory() + File.separator + folderName);
    if (directory.exists()) {
        files = directory.listFiles();
    }
    return files;
}

From source file:fr.paris.lutece.plugins.swaggerui.service.SwaggerFileService.java

/**
 * Find directories that contains swagger files
 * @param listSwaggerDirectories The directory list
 * @param parentDirectory The parent directory
 *//*from   w ww .  j a  va  2  s  .  c  o  m*/
private static void findDirectory(List<File> listSwaggerDirectories, File parentDirectory) {
    File[] listFiles = parentDirectory.listFiles();
    if (listFiles != null) {
        for (File file : listFiles) {
            if (file.isFile()) {
                continue;
            }
            if (file.getName().equals(SWAGGER_DIRECTORY_NAME)) {
                listSwaggerDirectories.add(file);
            }
            if (file.isDirectory()) {
                findDirectory(listSwaggerDirectories, file);
            }
        }
    }
}

From source file:Main.java

/**
 * delete files in directory//ww  w.  j a v a 2  s.c o  m
 *
 * @param directory
 */
private static void deleteFilesInDirectory(File directory) {
    if (directory != null && directory.exists() && directory.isDirectory()) {
        for (File item : directory.listFiles()) {
            if (item.isDirectory()) {
                deleteFilesInDirectory(item);
            } else {
                item.delete();
            }
        }
    }
}

From source file:Main.java

public static boolean deleteDir(File dir) {
    if (dir == null && !dir.exists()) {
        return false;
    }//from w  w  w .  j a  v a  2 s  .co  m
    if (dir.isDirectory()) {
        for (File file : dir.listFiles()) {
            boolean isSuccess = deleteDir(file);
            if (!isSuccess) {
                return false;
            }
        }
    }
    return dir.delete();
}

From source file:Main.java

/***
 * delete all logs/* w w  w  .  jav  a 2  s .co  m*/
 */
public static void deleteAllFiles() {
    File directory = new File(Environment.getExternalStorageDirectory() + File.separator + folderName);
    if (directory.exists()) {
        for (File file : directory.listFiles())
            file.delete();
    }
}

From source file:Main.java

public static void deleteRecursive(File paramFile) {
    if ((paramFile != null) && (paramFile.exists())) {
        if (paramFile.isDirectory()) {
            File[] arrayOfFile = paramFile.listFiles();
            int j = arrayOfFile.length;
            int i = 0;
            while (i < j) {
                deleteRecursive(arrayOfFile[i]);
                i += 1;/*from ww w . j  a  v a 2s.  c om*/
            }
        }
        paramFile.delete();
    }
}