List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
public static void getAllFileAndFolder(File folder, Set<File> all) { all.add(folder);/* w ww . j a v a 2s . co m*/ if (folder.isFile()) { return; } for (File file : folder.listFiles()) { all.add(file); if (file.isDirectory()) { getAllFileAndFolder(file, all); } } }
From source file:Main.java
/** * Returns album IDs containing at least one cached track. * @return Albums IDs// w w w . j a va 2 s. com */ public static Set<String> getCachedAlbumSet() { File cacheDir = getMusicCacheDir(); File[] albumList = cacheDir.listFiles(); Set<String> output = new HashSet<>(); for (File album : albumList) { if (album.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return filename.endsWith(".complete"); } }).length > 0) { output.add(album.getName()); } } return output; }
From source file:Main.java
public static ArrayList<File> getFilesInPath(String path) { File pathFile = new File(path); if (pathFile != null) { File[] files = pathFile.listFiles(); ArrayList<File> result = new ArrayList<>(); for (int i = 0; i < files.length; ++i) { result.add(files[i]);//from www . j a v a2s . c o m } result.add(0, pathFile.getParentFile()); return result; } else { return null; } }
From source file:Main.java
/** * DOC bZhou Comment method "searchAllFile". * // w ww. j a va 2s. c o m * @param result * @param parent * @param recursive * @param withFolder */ public static void searchAllFile(List<File> result, File parent, boolean recursive, boolean withFolder) { File[] files = parent.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && recursive) { if (withFolder) { result.add(file); } searchAllFile(result, file, recursive, withFolder); } else { result.add(file); } } } else { result.add(parent); } }
From source file:Main.java
public static Vector<String> loadScriptsInFolder(String path) { File fileScript = new File(path); Vector<String> vec = new Vector(); File files[] = fileScript.listFiles(); for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory()) vec.add(files[i].getAbsolutePath()); }//from w w w . j a v a2 s. co m return vec; }
From source file:Main.java
public static Vector<String> loadScriptsFolder(String path) { File fileScript = new File(path); Vector<String> vec = new Vector(); File files[] = fileScript.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) vec.add(files[i].getName()); }// w w w . j a va 2s . co m return vec; }
From source file:name.milesparker.gerrit.analysis.CollectGit.java
protected static void deleteContents(String dataDirectory) { File dir = new File(dataDirectory); for (File file : dir.listFiles()) { file.delete();//from w w w .ja v a 2s .co m } }
From source file:Main.java
/** * Get folder size recursively//from www . j a va2 s.c o m * @param directory File * @return long */ public static long getFolderSizeRecursively(File directory) { long length = 0; for (File file : directory.listFiles()) { if (file.isFile()) { length += file.length(); } else { length += getFolderSizeRecursively(file); } } return length; }
From source file:Main.java
public static long folderSize(File directory, boolean rootMode) { long length = 0; for (File file : directory.listFiles()) { if (file.isFile()) length += file.length();/*www .ja v a2 s. c om*/ else length += folderSize(file, rootMode); } return length; }
From source file:Main.java
public static void deleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) for (File child : fileOrDirectory.listFiles()) deleteRecursive(child);/* w w w. ja v a 2s. c o m*/ fileOrDirectory.delete(); }