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 List<File> getAll(String path) {
    File file = new File(path);
    if (!file.isDirectory())
        return new ArrayList<File>();
    return Arrays.asList(file.listFiles());
}

From source file:Main.java

/**
 * @param prodFile//www.j  a  va 2s . c  om
 * @return true if a module is inserted and recognized by BMI, false otherwise.
 */
private static boolean validBMIDeviceRoot(File prodFile) {
    if (!prodFile.exists() || !prodFile.isDirectory()) {
        return false;
    }

    return prodFile.listFiles().length > 0;
}

From source file:com.bluexml.tools.miscellaneous.ConvertFileContentIntoJSString.java

protected static void parseFile(File input, String fileNameout) {

    if (input.isDirectory()) {
        File[] listFiles = input.listFiles();
        for (File file2 : listFiles) {
            parseFile(file2, fileNameout);
        }//from ww w . j a  va2s .  c  om
    } else {
        File output = new File(input.getParentFile(), input.getName() + "-" + fileNameout);
        writeFiles(input, output);
    }

}

From source file:de.akquinet.android.rindirect.Main.java

/**
 * Traverse the 'gen' folder to find the R.java file.
 * @param gen the gen folder/*from   w  w w  .  j a v  a 2  s.  c o  m*/
 * @return the R file of <code>null</code> if not found
 */
private static File findR(File gen) {
    File[] files = gen.listFiles();
    for (File f : files) {
        if (f.isDirectory()) {
            return findR(f);
        } else {
            if ("R.java".equals(f.getName())) {
                return f;
            }
        }
    }
    return null;
}

From source file:Utils.java

private static List<File> getFilesRecurse(File dir, Pattern pattern, File exclude, boolean rec,
        List<File> fileList) {
    for (File file : dir.listFiles()) {
        if (file.equals(exclude)) {
            continue;
        }/*from w  ww  .  j a v  a 2  s .  c  o  m*/
        if (file.isDirectory() && rec) {
            getFilesRecurse(file, pattern, exclude, rec, fileList);
        } else {
            Matcher m = pattern.matcher(file.getName());
            if (m.matches()) {
                fileList.add(file);
            }
        }
    }
    return fileList;
}

From source file:Main.java

public static boolean deleteDirectory(File directory) throws Exception {
    try {/*from w  w  w.  ja  v a 2s. c  o m*/
        if (directory.exists()) {
            File[] files = directory.listFiles();
            for (int i = 0; i < files.length; i++)
                if (files[i].isDirectory())
                    deleteDirectory(files[i]);
                else
                    files[i].delete();
        }
    } catch (Exception e) {
        throw new Exception(new StringBuilder().append("Error occurred while trying to delete directory ")
                .append(directory).toString());
    }
    return directory.delete();
}

From source file:Main.java

public static void getFileList(final List<File> fileList, final File root, final File[] ignoreList) {
    final File[] list = root.listFiles();

    if (list == null) {
        return;//from  ww w  . j  av a  2  s.  c om
    }

    for (final File f : list) {
        if (f.isDirectory() && !isIgnored(ignoreList, f)) {
            getFileList(fileList, f, ignoreList);
        } else {
            String filename = getFileExt(f.getName());

            if (filename.equalsIgnoreCase("jpg") || filename.equalsIgnoreCase("png")
                    || filename.equalsIgnoreCase("mp4")) {
                fileList.add(f);
            }
        }
    }
}

From source file:Main.java

public static void deleteNoBackupApk(List<String> apkNames) {
    boolean isExist;
    File directory = new File(BACKUPPATH);
    if (directory.exists()) {
        File[] files = directory.listFiles();
        for (int i = 0; i < files.length; i++) {
            isExist = false;/*from w  w w . j  a  v a2s.co m*/
            for (int j = 0; j < apkNames.size(); j++) {
                String tempName = files[i].getName();
                tempName = tempName.substring(0, tempName.length() - 4);
                if (tempName.equals(apkNames.get(j))) {
                    isExist = true;
                    break;
                }
            }
            if (!isExist) {
                files[i].delete();
            }

        }
    }
}

From source file:Main.java

public static void cleanDirectory(File file) {
    if (!file.exists()) {
        return;/*from www . j a va 2s .  c o  m*/
    }
    File[] contentFiles = file.listFiles();
    if (contentFiles != null) {
        for (File contentFile : contentFiles) {
            try {
                delete(contentFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

private static void zipFile(ZipOutputStream zipOutputStream, String sourcePath) throws IOException {

    java.io.File files = new java.io.File(sourcePath);
    java.io.File[] fileList = files.listFiles();

    String entryPath = "";
    BufferedInputStream input = null;
    for (java.io.File file : fileList) {
        if (file.isDirectory()) {
            zipFile(zipOutputStream, file.getPath());
        } else {//from   w w  w.  j  ava  2  s  .co  m
            byte data[] = new byte[BUFFER_SIZE];
            FileInputStream fileInputStream = new FileInputStream(file.getPath());
            input = new BufferedInputStream(fileInputStream, BUFFER_SIZE);
            entryPath = file.getAbsolutePath().replace(parentPath, "");

            ZipEntry entry = new ZipEntry(entryPath);
            zipOutputStream.putNextEntry(entry);

            int count;
            while ((count = input.read(data, 0, BUFFER_SIZE)) != -1) {
                zipOutputStream.write(data, 0, count);
            }
            input.close();
        }
    }

}