List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
public static void deleteFileDirectory(File file) { if (!file.exists()) { return;/*from w ww. java 2s . c om*/ } if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null || files.length == 0) { file.delete(); return; } for (int i = 0, length = files.length; i < length; i++) { files[i].delete(); } file.delete(); } }
From source file:Main.java
public static void zipChildren(File folder, String prefix, ZipOutputStream out) throws IOException { File[] files = folder.listFiles(); if (files == null) return;//from w w w . ja va2s . c o m for (File file : files) { if (file.isFile()) { String name = prefix + file.getName(); ZipEntry entry = new ZipEntry(name); entry.setTime(file.lastModified()); out.putNextEntry(entry); loadFromFile(file, out); out.closeEntry(); } else if (file.isDirectory()) { zipChildren(file, prefix + file.getName() + "/", out); } } }
From source file:com.ibm.liberty.starter.StarterUtil.java
/** * Generate the list of files in the directory and all of its sub-directories (recursive) * /*from w w w . ja v a 2 s . co m*/ * @param dir - The directory * @param filesListInDir - List to store the files */ public static void populateFilesList(File dir, List<File> filesListInDir) { File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { filesListInDir.add(file); } else { populateFilesList(file, filesListInDir); } } }
From source file:Main.java
public static Collection<String> getXmlFilenames(String path) throws NullPointerException { Collection<String> results = new ArrayList<>(); File folder = new File(path); // We will grab all XML files from the target directory. File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { String file;// w ww.j av a 2 s . com for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { file = listOfFiles[i].getAbsolutePath(); if (file.endsWith(".xml") || file.endsWith(".xml")) { results.add(file); } } } } return results; }
From source file:Main.java
public static Collection<String> getXmlFilenames(String path) throws NullPointerException { Collection<String> results = new ArrayList<>(); File folder = new File(path); // We will grab all XML files from the target directory. File[] listOfFiles = folder.listFiles(); String file;/*w w w.j av a 2 s . c o m*/ for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { file = listOfFiles[i].getAbsolutePath(); if (file.endsWith(".xml") || file.endsWith(".xml")) { results.add(file); } } } return results; }
From source file:Main.java
public static void deleteDirectoryTree(File fileOrDirectory) // delete everything in folder - recursively { if (fileOrDirectory.isDirectory()) { for (File child : fileOrDirectory.listFiles()) { deleteDirectoryTree(child);//from w w w . jav a 2 s . co m } } fileOrDirectory.delete(); }
From source file:com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.java
private static void delete(File f) { if (f.isDirectory()) { for (File child : f.listFiles()) { delete(child);//from ww w . ja v a 2 s . c om } } f.delete(); }
From source file:Main.java
public static void deleteDir() { File dir = new File(SDPATH); if (dir == null || !dir.exists() || !dir.isDirectory()) return;//from w w w .j ava2 s . c o m for (File file : dir.listFiles()) { if (file.isFile()) file.delete(); else if (file.isDirectory()) deleteDir(); } dir.delete(); }
From source file:com.codefollower.lealone.omid.TestUtils.java
public static void delete(File f) throws IOException { if (f.isDirectory()) { for (File c : f.listFiles()) delete(c);/* w ww .ja v a2s.c o m*/ } if (!f.delete()) throw new FileNotFoundException("Failed to delete file: " + f); }
From source file:Main.java
static public boolean deleteDirectory(File path) { if (path == null) return false; if (path.exists()) { File[] files = path.listFiles(); if (files == null) { return true; }/*from w w w. ja va 2 s .c o m*/ for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return (path.delete()); }