List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
private static void deleteFileOrDirectory(File file) { if (file.isDirectory()) { File[] subFiles = file.listFiles(); for (File sf : subFiles) { if (sf.isFile()) sf.delete();//from w w w .j a v a 2 s .co m else deleteFileOrDirectory(sf); } } file.delete(); }
From source file:Main.java
public static boolean removeTagsListCache(File cacheDir) { boolean flag = false; File[] filesList = cacheDir.listFiles(); for (int i = 0; i < filesList.length; i++) { if (filesList[i].isDirectory() && filesList[i].toString().equals("files")) { removeTagsListCache(filesList[i]); } else {/*from w w w .j a v a2s . c om*/ filesList[i].delete(); flag = true; } } return flag; }
From source file:Main.java
public static void deleteFileInDirectory(File file) { if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { files[i].delete();//from w w w. j av a 2 s. c om } else { deleteFileInDirectory(files[i]); } } } else { file.delete(); } }
From source file:Main.java
public static File[] getFilesFromDir(String dirName) { File file = new File(dirName); if (file.exists()) { File[] files = file.listFiles(); return files; }//from w w w.j a v a2 s . c o m return null; }
From source file:Main.java
/** * Deletes the contents of {@code dir}. Throws an IOException if any file * could not be deleted, or if {@code dir} is not a readable directory. *//* w ww .j ava2s . c o m*/ static void deleteContents(File dir) throws IOException { File[] files = dir.listFiles(); if (files == null) { throw new IOException("not a readable directory: " + dir); } for (File file : files) { if (file.isDirectory()) { deleteContents(file); } if (!file.delete()) { throw new IOException("failed to delete file: " + file); } } }
From source file:Main.java
private static void cleanDir(File dir, long bytes) { long bytesDeleted = 0; File[] files = dir.listFiles(); for (File file : files) { bytesDeleted += file.length();/*from w w w . j a v a 2s . c o m*/ file.delete(); if (bytesDeleted >= bytes) { break; } } }
From source file:Main.java
private static void deleteFileOrDirectory(File file) { if (file.isDirectory()) { File[] subFiles = file.listFiles(); for (File sf : subFiles) { if (sf.isFile()) { sf.delete();//from w w w. ja v a 2 s .c o m } else { deleteFileOrDirectory(sf); } } } file.delete(); }
From source file:Main.java
public static void deleteAllFromPath(String path) { File folder = new File(path); if (null != folder) { File[] files = folder.listFiles(); for (File file : files) file.delete();// w ww .j av a 2 s. co m } }
From source file:Main.java
public static void deleteDir(File file) { if (file.isDirectory()) { for (File _file : file.listFiles()) { if (_file.isDirectory()) { deleteDir(_file);/*from w ww . j a v a2s. com*/ } else { _file.delete(); } } } else { file.delete(); } }
From source file:Main.java
public static File[] getFilesDirectorio(String nombreDirectorio) { File directorio = new File(nombreDirectorio); File[] files = directorio.listFiles(); ArrayList<File> filtro = new ArrayList<File>(); if (files != null) for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { filtro.add(files[i]);/*ww w. j a v a2 s .co m*/ } } return filtro.toArray(new File[filtro.size()]); }