List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
public static long getFolderSize(File file) throws Exception { long size = 0; File[] fileList = file.listFiles(); for (File f : fileList) { if (f.isDirectory()) { size += getFolderSize(f);//from w w w .ja v a 2s . c om } else { size += f.length(); } } return size; }
From source file:Main.java
public static void innerListFiles(Collection<File> files, File directory, FileFilter filter) { File[] found = directory.listFiles(); if (found != null) { for (File aFound : found) { if (aFound.isDirectory()) { innerListFiles(files, aFound, filter); } else { File[] found2 = directory.listFiles(filter); Collections.addAll(files, found2); }/*from w w w .j ava 2 s.c o m*/ } } }
From source file:Main.java
public static long getFolderSize(File dir) { long size = 0; try {/*from www.j a va 2 s.c o m*/ File[] fileList = dir.listFiles(); for (int i = 0; i < fileList.length; i++) { if (fileList[i].isDirectory()) { size += getFolderSize(fileList[i]); } else { size += fileList[i].length(); } } } catch (Exception e) { e.printStackTrace(); } return size; }
From source file:Main.java
public static int findNextSequence(String path, String seqFileNamePrefix, String seqFileNameSuffix) { int seq = 0;/*from w w w. j a va 2 s.c o m*/ File[] child = null; try { File dir = new File(path); child = dir.listFiles(); } catch (Exception e) { child = null; } if (child == null) { } else { for (int i = 0; i < child.length; i++) { String fileName = child[i].getName(); int pre = fileName.indexOf(seqFileNamePrefix) + seqFileNamePrefix.length(); int suf = fileName.lastIndexOf(seqFileNameSuffix); int sufLen = seqFileNameSuffix.length(); String val_s = ""; try { int val = 0; if ((pre >= 0) && (suf >= 0) && (suf > pre) && ((suf + sufLen) == fileName.length())) { val_s = fileName.substring(pre, suf); val = Integer.parseInt(val_s); } if (val > seq) seq = val; } catch (Exception e) { } } } return seq + 1; }
From source file:Main.java
protected static void delFiles(File file) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (int i = 0, size = files.length; i < size; i++) { File f = files[i]; delFiles(f);//from w w w. ja va 2 s .co m } } } else { file.delete(); } }
From source file:Main.java
public static long getFolderSize(File f) { long size = 0; if (f.isDirectory()) { for (File file : f.listFiles()) { size += getFolderSize(file); }//from ww w .jav a2 s.co m } else { size = f.length(); } return size; }
From source file:Main.java
public static boolean deleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) { for (File child : fileOrDirectory.listFiles()) { deleteRecursive(child);/*from w ww . j a va 2s . c om*/ } } return fileOrDirectory.delete() || !fileOrDirectory.exists(); }
From source file:Main.java
private static void removeDirectory(File directory) { if (directory.isDirectory()) { File[] files = directory.listFiles(); for (int i = 0; i < files.length; ++i) { if (files[i].isDirectory()) { removeDirectory(files[i]); }/*from ww w .j a v a 2s. c o m*/ files[i].delete(); } directory.delete(); } }
From source file:Main.java
static public boolean deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); if (files == null) { return true; }//w w w . j a v a 2s . co m for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return path.delete(); }
From source file:Main.java
public static List<String> getAllSkinZipFiles(String path) { List<String> zipFiles = new ArrayList<String>(); File file = new File(path); if (file.exists()) { File[] files = file.listFiles(); if (files.length > 0) { for (File f : files) { if (f.getName().startsWith("skin") && f.getName().endsWith("zip")) { zipFiles.add(f.getAbsolutePath()); }//from ww w. j av a2 s .co m } } } return zipFiles; }