List of usage examples for java.io File list
public String[] list()
From source file:Main.java
public static boolean delAllFile(String path) { boolean flag = false; File file = new File(path); if (!file.exists()) { return flag; }/*from w w w .j a v a 2s . co m*/ if (!file.isDirectory()) { return flag; } String[] tempList = file.list(); File temp = null; for (int i = 0; i < tempList.length; i++) { if (path.endsWith(File.separator)) { temp = new File(path + tempList[i]); } else { temp = new File(path + File.separator + tempList[i]); } if (temp.isFile()) { temp.delete(); } if (temp.isDirectory()) { delAllFile(path + "/" + tempList[i]); flag = true; } } return flag; }
From source file:Main.java
public static void deleteChildrenIgnoreFirstLevel(File target, String strIgnore) throws IOException { if (!target.exists()) return;/*from w w w. j av a 2 s.co m*/ if (target.isDirectory()) { String[] children = target.list(); for (int i = 0; i != children.length; ++i) { File f = new File(target, children[i]); if (f.isDirectory()) deleteRecursively(f); else if (!f.getName().startsWith(strIgnore)) { if (!f.delete()) throw new IOException("Can not delete " + f.getAbsolutePath()); } } } }
From source file:com.netsteadfast.greenstep.util.FSUtils.java
public static String[] getList(final String dir) { File directory = new File(dir); return directory.list(); }
From source file:Main.java
public static long getFileSize(File file) throws Throwable { if (!file.exists()) { return 0L; } else if (!file.isDirectory()) { return file.length(); } else {/*from w w w . j a v a 2 s. c om*/ String[] names = file.list(); int size = 0; for (int i = 0; i < names.length; ++i) { File f = new File(file, names[i]); size = (int) ((long) size + getFileSize(f)); } return (long) size; } }
From source file:Main.java
public static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isDirectory()) { String[] listfile = newPath.list(); // delete all files within the specified directory and then // delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); }/* w w w . j a v a2 s .c om*/ newPath.delete(); Log.i("DirectoryManager deleteDirectory", fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }
From source file:net.geoprism.gis.geoserver.CleanupFacade.java
@Transaction private static void cleanupUnusedFiles_Transaction() { File root = new File(new File(VaultProperties.getPath("vault.default")), "files"); if (!root.exists()) { String[] list = root.list(); if (list != null && list.length > 0) { LinkedList<String> names = new LinkedList<String>(Arrays.asList(list)); new Iterables<String>().remove(names, new SessionPredicate()); for (String name : names) { File directory = new File(new File(VaultProperties.getPath("vault.default"), "files"), name); try { FileUtils.deleteDirectory(directory); } catch (IOException e) { throw new ProgrammingErrorException(e); }// www . j a v a 2 s . co m } } } }
From source file:Main.java
public static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isDirectory()) { String[] listfile = newPath.list(); // delete all files within the specified directory and then // delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); }//from ww w .j ava 2 s . c o m newPath.delete(); Log.d(TAG, "DirectoryManager deleteDirectory" + fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }
From source file:S3DataManager.java
public static void zipSource(final String directory, final ZipOutputStream out, final String prefixToTrim) throws Exception { if (!Paths.get(directory).startsWith(Paths.get(prefixToTrim))) { throw new Exception(zipSourceError + "prefixToTrim: " + prefixToTrim + ", directory: " + directory); }// w w w .j ava 2 s. com File dir = new File(directory); String[] dirFiles = dir.list(); if (dirFiles == null) { throw new Exception("Invalid directory path provided: " + directory); } byte[] buffer = new byte[1024]; int bytesRead; for (int i = 0; i < dirFiles.length; i++) { File f = new File(dir, dirFiles[i]); if (f.isDirectory()) { if (f.getName().equals(".git") == false) { zipSource(f.getPath() + File.separator, out, prefixToTrim); } } else { FileInputStream inputStream = new FileInputStream(f); try { String path = trimPrefix(f.getPath(), prefixToTrim); ZipEntry entry = new ZipEntry(path); out.putNextEntry(entry); while ((bytesRead = inputStream.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } } finally { inputStream.close(); } } } }
From source file:com.opensymphony.util.FileUtils.java
public final static String[] dirList(File path) { String[] list;//ww w . ja v a2s .c om list = path.list(); return list; }
From source file:be.vds.jtbdive.core.utils.FileUtilities.java
/** * Deletes all files and subdirectories under dir. Returns true if all * deletions were successful. If a deletion fails, the method stops * attempting to delete and returns false. *///from w ww . j av a 2 s . c o m public static boolean deleteDir(File dir) { if (dir.exists() && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; } } } // The directory is now empty so delete it return dir.delete(); }