List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
protected static void delFiles(File file, String keep) { 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, keep);/*from w w w. j ava 2 s . c o m*/ } } } else { if (keep.equals(file.getPath())) return; file.delete(); } }
From source file:Main.java
public static void recursiveDelete(File file) { if (file == null) { return;//from ww w.j a v a2s . c om } File[] files = file.listFiles(); if (files != null) { for (File each : files) { recursiveDelete(each); } } file.delete(); }
From source file:com.github.lucene.store.CreateJavaTestIndex.java
private static void findFiles(final List<File> result, final File dir) { for (final File file : dir.listFiles()) { if (file.getName().endsWith(".java")) { result.add(file);/*from ww w . j a v a2s . c o m*/ } else if (file.isDirectory()) { findFiles(result, file); } } }
From source file:Main.java
public static int deleteFiles(Collection<File> files) { int n = 0;// w w w .ja v a 2 s . c o m for (File file : files) { if (file.isDirectory()) { n += deleteFiles(Arrays.asList(file.listFiles())); } if (file.delete()) n++; } return n; }
From source file:Main.java
public static void reNameSuffix(File dir, String oldSuffix, String newSuffix) { if (dir.isDirectory()) { File[] listFiles = dir.listFiles(); for (int i = 0; i < listFiles.length; i++) { reNameSuffix(listFiles[i], oldSuffix, newSuffix); }/*w w w . j av a 2s.c o m*/ } else { dir.renameTo(new File(dir.getPath().replace(oldSuffix, newSuffix))); } }
From source file:Main.java
public static long getTotalSizeOfFilesInDir(final File file) { if (file.isFile()) return file.length(); final File[] children = file.listFiles(); long total = 0; if (children != null) for (final File child : children) total += getTotalSizeOfFilesInDir(child); return total; }
From source file:Utils.java
/** * Deletes a directory.//from w ww . j a v a 2s . c o m * * @param dir the file for the directory to delete * @return true if susscess */ public static boolean deleteDir(File dir) { if (dir.isDirectory()) { for (File file : dir.listFiles()) { if (file.isDirectory()) { try { if (file.getCanonicalFile().getParentFile().equals(dir.getCanonicalFile())) { deleteDir(file); if (file.exists() && !file.delete()) { System.out.println("Can't delete: " + file); } } else { System.out.println("Warning: " + file + " may be a symlink. Ignoring."); } } catch (IOException e) { System.out.println("Warning: Cannot determine canonical file for " + file + " - ignoring."); } } else { if (file.exists() && !file.delete()) { System.out.println("Can't delete: " + file); } } } return dir.delete(); } return false; }
From source file:com.qait.automation.samjbehavedemo.utils.FileHandler.java
public static File[] getAllFiles(String directory) { File files = getFile(directory); return files.listFiles(); }
From source file:com.qait.automation.samjbehavedemo.utils.FileHandler.java
public static int getFilesCount(String directory) { File files = getFile(directory); return files.listFiles().length; }
From source file:Main.java
private static void deleteContent(File dir, boolean deleteDir) { if (dir.isDirectory()) { File[] files = dir.listFiles(); if (files != null && files.length > 0) { for (File file : files) { deleteContent(file, true); }// ww w .j a v a 2s.co m } } if (deleteDir) dir.delete(); }