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 deleteFileByDirectory(File directory) {
    if (directory.exists() && directory.isDirectory()) {
        for (File file : directory.listFiles()) {
            file.delete();/*  w  ww .  j a va  2 s  . c o  m*/
        }
    }
}

From source file:Main.java

/**
 * Gets the opf file name.//from   w ww. jav a2 s .com
 * 
 * @param path the folder contains file opf.
 * @return the opf file name
 */
public static String getOpfFileName(String path) {
    String fileName = null;
    File folder = new File(path);
    if (folder.isDirectory()) {
        File[] listOfFiles = folder.listFiles();
        if (listOfFiles != null) {
            for (File file : listOfFiles) {
                if (file.isFile() && file.getName().endsWith(".opf")) {
                    fileName = file.getName();
                    break;
                }
            }
        }
    }
    return fileName;
}

From source file:Main.java

public static void deleteFile(File file) {
    if (file == null) {
        return;//  www.  j  a v  a 2 s.  c o m
    }
    if (file.isDirectory() && file.listFiles() != null) {
        for (File item : file.listFiles()) {
            deleteFile(item);
        }
    }
    try {
        file.delete();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return;
}

From source file:Main.java

public static List<String> ListFile() {

    File file = new File(Environment.getExternalStorageDirectory() + "/rectPhoto/");
    File[] f = file.listFiles();
    List<String> datas = new ArrayList<String>();
    //      String Path[] = new String[f.length];
    for (int i = 0; i < f.length; i++) {

        //         Path[i] = f[i].getPath();
        datas.add(f[i].getPath());/*from  w  w w. j  a  va 2s.  c  o  m*/
    }

    return datas;

}

From source file:Main.java

public static double getSize(File file) {
    if (file.exists()) {
        if (!file.isFile()) {
            File[] fl = file.listFiles();
            double ss = 0;
            for (File f : fl) {
                ss += getSize(f);/*w w  w  .j a  v a2  s  . co  m*/
            }
            return ss;
        } else {
            double ss = (double) file.length() / 1024 / 1024;
            return ss;
        }
    } else {
        return 0.0;
    }
}

From source file:com.mycompany.hdp.hdp.java

private static void copyFilesToDir(String srcDirPath, FileSystem fs, String destDirPath) throws IOException {
    File dir = new File(srcDirPath);
    for (File file : dir.listFiles()) {
        fs.copyFromLocalFile(new Path(file.getPath()), new Path(destDirPath, file.getName()));
    }/*from   www .j  a  va2 s . c  om*/
}

From source file:Main.java

public static void deleteDir(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File subFile : files) {
                if (subFile.isDirectory())
                    deleteDir(subFile);/*from w ww  . ja v  a2 s  .  c  o m*/
                else
                    subFile.delete();
            }
        }
        file.delete();
    }
}

From source file:Main.java

public static boolean checkBackupApkIsExist(String apkName) {
    boolean isExist = false;
    File directory = new File(BACKUPPATH);
    if (directory.exists()) {
        File[] files = directory.listFiles();
        for (int i = 0; i < files.length; i++) {
            String tempName = files[i].getName();
            tempName = tempName.substring(0, tempName.length() - 4);
            if (tempName.equals(apkName)) {
                isExist = true;//from  www. j a v  a 2 s .  c  o  m
                break;
            }
        }
    }
    return isExist;

}

From source file:Util.java

public static boolean recursiveDeleteFile(File path) {
    if (path.exists()) {
        if (path.isDirectory()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    recursiveDeleteFile(files[i]);
                } else {
                    files[i].delete();//  w w  w.  j ava 2  s .co  m
                }
            }
        }
    }
    return (path.delete());
}

From source file:Main.java

public static List<File> getListFiles(File parentDir) {
    ArrayList<File> inFiles = new ArrayList<File>();
    File[] files = parentDir.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            inFiles.addAll(getListFiles(file));
        } else {//from  www .j  av  a 2 s .  c o m
            inFiles.add(file);
        }
    }
    return inFiles;
}