List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
public static long getFileSize(File f) throws Exception { long size = 0; File flist[] = f.listFiles(); for (int i = 0; i < flist.length; i++) { if (flist[i].isDirectory()) { size = size + getFileSize(flist[i]); } else {/*ww w. ja v a 2s.co m*/ size = size + flist[i].length(); } } return size; }
From source file:Utils.java
/** * Count files in a directory (including files in all subdirectories) * @param directory the directory to start in * @return the total number of files/*www. j av a 2 s .c o m*/ */ public static int countFilesInDirectory(File directory) { int count = 0; for (File file : directory.listFiles()) { if (file.isFile()) { count++; } if (file.isDirectory()) { count += countFilesInDirectory(file); } } return count; }
From source file:Main.java
public static long getFileFolderSize(File f) throws Exception { long size = 0; File flist[] = f.listFiles(); for (int i = 0; i < flist.length; i++) { if (flist[i].isDirectory()) { size = size + getFileFolderSize(flist[i]); } else {// w w w . j a v a 2 s . c om size = size + flist[i].length(); } } return size; }
From source file:Main.java
public static void deleteRecyle(File file) { if (file.isDirectory()) { for (File childFile : file.listFiles()) { deleteRecyle(childFile);//from w ww . jav a2s. co m } } file.delete(); }
From source file:Main.java
public static void deleteFile(File oldPath) { if (oldPath.isDirectory()) { File[] files = oldPath.listFiles(); for (File file : files) { deleteFile(file);//from ww w .ja va2s . com } } oldPath.delete(); }
From source file:Main.java
synchronized public static int clearFolder(File path) { int deletedItems = 0; File[] fileList = path.listFiles(); if (fileList != null) { for (File file : fileList) { if (file.isDirectory()) { deletedItems += clearFolder(file); }//from w w w. j av a 2s . c o m if (file.delete()) { deletedItems++; } } } return deletedItems; }
From source file:Main.java
public static long getFolderSize(java.io.File file) { long size = 0; java.io.File[] fileList = file.listFiles(); for (int i = 0; i < fileList.length; i++) { if (fileList[i].isDirectory()) { size = size + getFolderSize(fileList[i]); } else {// www . j ava2 s . co m size = size + fileList[i].length(); } } return size; }
From source file:Main.java
public static ArrayList<File> getFilesArray(String path) { File file = new File(path); File files[] = file.listFiles(); ArrayList<File> listFile = new ArrayList<File>(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { listFile.add(files[i]);/* ww w . java2 s.c o m*/ } if (files[i].isDirectory()) { listFile.addAll(getFilesArray(files[i].toString())); } } } return listFile; }
From source file:Main.java
public static void deleteEmptyDir(File file) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null && files.length > 0) { for (File tempFile : files) { deleteEmptyDir(tempFile); deleteEmptyDir(tempFile); }// w w w. j a v a 2s . c o m } else { file.delete(); } } }
From source file:Main.java
public static void deleteDirectory(File f) { if (f.isDirectory()) { for (File c : f.listFiles()) deleteDirectory(c);//from w w w .j av a 2 s. com } f.delete(); }