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 purgeMediaPath(String mediaPath) {
    File tempMediaFolder = new File(mediaPath);
    File[] tempMediaFiles = tempMediaFolder.listFiles();
    if (tempMediaFiles == null || tempMediaFiles.length == 0) {
        deleteAndReport(tempMediaFolder);
    } else {//from   w ww.j a v  a  2s  .  c o m
        for (File tempMediaFile : tempMediaFiles) {
            deleteAndReport(tempMediaFile);
        }
    }
}

From source file:com.docudile.app.services.utils.FileHandler.java

private static ArrayList<String> getFilePaths(String folderPath) {
    ArrayList<String> filenames = new ArrayList<>();
    File folder = new File(folderPath);

    for (File filename : folder.listFiles()) {
        if (filename.isFile()) {
            filenames.add(filename.getName());
        }//from   w  w  w .  ja  v a 2s.co  m
    }
    return filenames;
}

From source file:hrider.io.FileHelper.java

public static File findFile(File folder, Pattern regex) {
    File[] files = folder.listFiles();
    if (files != null) {
        for (File file : files) {
            if (regex.matcher(file.getName()).find()) {
                return file;
            }//from   w w w .j  av  a2 s  . c  o m
        }
    }
    return null;
}

From source file:Main.java

public static void deleteFiles(String relativePath) {
    //      File dir = new File(path);
    File dir = creatSDDir(relativePath);
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            file.delete();//from  ww  w .j av a  2 s .c om
        }
    }
}

From source file:Main.java

/**
 * recursively delete/*from   w ww.  j a  va  2 s  . c  o  m*/
 *
 * @param dir
 * @throws java.io.IOException
 */
public static void deleteDirectoryRecursively(File dir) throws IOException {
    File[] files = dir.listFiles();
    if (files == null) {
        throw new IllegalArgumentException("not a directory: " + dir);
    }
    for (File file : files) {
        if (file.isDirectory()) {
            deleteDirectoryRecursively(file);
        }
        if (!file.delete()) {
            throw new IOException("failed to delete file: " + file);
        }
    }
}

From source file:Main.java

public static DefaultMutableTreeNode addNodes(File dir) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(dir);
    for (File file : dir.listFiles()) {
        if (file.isDirectory()) {
            node.add(addNodes(file));/*w w  w  .  jav  a 2  s.  c  o m*/
        } else {
            node.add(new DefaultMutableTreeNode(file));
        }
    }
    return node;
}

From source file:Main.java

public static void rmDir(File dir) throws IOException {
    if (dir.exists()) {
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (!files[i].delete()) {
                throw new IOException("could not delete " + files[i]);
            }/*www .  jav a  2 s  .  c  om*/
        }
        dir.delete();
    }
}

From source file:Main.java

public static void deleteFile(File f) {
    if (f.isDirectory()) {
        File[] files = f.listFiles();
        if (files != null && files.length > 0) {
            for (int i = 0; i < files.length; ++i) {
                deleteFile(files[i]);//from  w  w w .  j a v  a2 s .c  om
            }
        }
    }
    f.delete();
}

From source file:Main.java

protected static void cleanUpFileDirectory() {
    if (c == null) // no application context exists
        return;/*from  w w w.  j a va 2 s .  c  om*/

    ContextWrapper cw = new ContextWrapper(c.getApplicationContext());
    File directory = cw.getDir(IMAGE_DIR, Context.MODE_PRIVATE);

    File file[] = directory.listFiles();
    for (int i = 0; i < file.length; i++) {
        if (file[i].lastModified() + MAXFILEAGE < System.currentTimeMillis()) {
            file[i].delete();
        }
    }
}

From source file:Main.java

public static void deleteFile(String path) {
    File file = new File(path);
    if (file.isDirectory()) {//delete dir
        File[] childFile = file.listFiles();
        for (File tempFile : childFile) {
            tempFile.delete();//from  w ww  .  j av a 2 s . com
        }
        file.delete();
    } else {//delete file
        file.delete();
    }
}