List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
public static String getDictName(String dictFolderPath) { String dictName = null;//from w w w . j a v a2 s.co m File f = new File(dictFolderPath); if (!f.exists()) return null; File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { if (files[i].getName().endsWith(".ifo")) { dictName = files[i].getName().replace(".ifo", ""); break; } } } return dictName; }
From source file:Main.java
public static boolean removeDir(File dirFile) { if (!dirFile.isDirectory()) { return false; }//from w w w.j ava2 s . co m File files[] = dirFile.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { break; } if (!files[i].delete()) { return false; } } return true; }
From source file:Main.java
public static int getNumOfFiles(String dirPath) { File dir = new File(dirPath); if (!dir.isDirectory()) { return 0; }//from ww w .j a va 2 s . c o m File[] files = dir.listFiles(); int numOfFiles = 0; for (File f : files) { if (f.isFile()) { numOfFiles++; } } return numOfFiles; }
From source file:Main.java
private static void readGpxDirectory(File dir, final List<String> list, String parent) { if (dir != null && dir.canRead()) { File[] files = dir.listFiles(); if (files != null) { for (File f : files) { if (f.getName().toLowerCase().endsWith(".gpx")) { //$NON-NLS-1$ list.add(parent + f.getName()); } else if (f.isDirectory()) { readGpxDirectory(f, list, parent + f.getName() + "/"); }/*from ww w . jav a 2s.c o m*/ } } } }
From source file:Main.java
/** * Local Folder size// ww w.j a va 2 s. c om * @param dir File * @return Size in bytes */ public static long getFolderSize(File dir) { if (dir.exists()) { long result = 0; File[] fileList = dir.listFiles(); for (int i = 0; i < fileList.length; i++) { if (fileList[i].isDirectory()) { result += getFolderSize(fileList[i]); } else { result += fileList[i].length(); } } return result; } return 0; }
From source file:Main.java
public static boolean deleteFileDir(File dir) { if (dir == null) { return true; }/* w w w . jav a 2s . c om*/ File[] fList = dir.listFiles(); if (fList == null || fList.length <= 0) { return true; } for (File file : fList) { if (file == null) { continue; } if (file.isDirectory()) { if (!deleteFileDir(file)) { return false; } } else { if (!file.delete()) { return false; } } } return true; }
From source file:Main.java
public static void deleteDir() { File dir = new File(SD_PATH); if (!dir.exists() || !dir.isDirectory()) return;// w w w . j a v a 2 s.c om for (File file : dir.listFiles()) { if (file.isFile()) file.delete(); else if (file.isDirectory()) deleteDir(); } dir.delete(); }
From source file:Main.java
public static void recursiveFileRemoval(File root) { if (!root.delete()) { if (root.isDirectory()) { File[] files = root.listFiles(); if (files != null) { for (File f : files) { recursiveFileRemoval(f); }/* ww w . j a v a2 s . c o m*/ } } } }
From source file:Main.java
private static long getDirSize(File dir) { long size = 0; if (!dir.exists()) { dir.mkdir();/*from ww w .j a v a2s.c o m*/ } File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { size += file.length(); } } return size; }
From source file:Main.java
/** * Remove an album from the cache.//from w w w . j a v a 2 s .c o m * @param albumId Album ID */ public static void removeAlbum(String albumId) { File albumDir = new File(getMusicCacheDir(), albumId); if (albumDir.exists()) { for (File file : albumDir.listFiles()) { file.delete(); } albumDir.delete(); } }