List of usage examples for java.io File list
public String[] list()
From source file:Main.java
public static boolean deleteDir(File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (String aChildren : children) { boolean success = deleteDir(new File(dir, aChildren)); if (!success) { return false; }/*from w w w. j a v a2 s .c om*/ } } // The directory is now empty so delete it return dir != null && dir.delete(); }
From source file:FileTableHTML.java
public static String makeHTMLTable(String dirname) { // Look up the contents of the directory File dir = new File(dirname); String[] entries = dir.list(); // Set up an output stream we can print the table to. // This is easier than concatenating strings all the time. StringWriter sout = new StringWriter(); PrintWriter out = new PrintWriter(sout); // Print the directory name as the page title out.println("<H1>" + dirname + "</H1>"); // Print an "up" link, unless we're already at the root String parent = dir.getParent(); if ((parent != null) && (parent.length() > 0)) out.println("<A HREF=\"" + parent + "\">Up to parent directory</A><P>"); // Print out the table out.print("<TABLE BORDER=2 WIDTH=600><TR>"); out.print("<TH>Name</TH><TH>Size</TH><TH>Modified</TH>"); out.println("<TH>Readable?</TH><TH>Writable?</TH></TR>"); for (int i = 0; i < entries.length; i++) { File f = new File(dir, entries[i]); out.println("<TR><TD>" + (f.isDirectory() ? "<a href=\"" + f + "\">" + entries[i] + "</a>" : entries[i]) + "</TD><TD>" + f.length() + "</TD><TD>" + new Date(f.lastModified()) + "</TD><TD align=center>" + (f.canRead() ? "x" : " ") + "</TD><TD align=center>" + (f.canWrite() ? "x" : " ") + "</TD></TR>"); }/*from ww w. j ava 2s . c o m*/ out.println("</TABLE>"); out.close(); // Get the string of HTML from the StringWriter and return it. return sout.toString(); }
From source file:eu.planets_project.services.utils.test.FileAccess.java
private static void index(File root, Map<String, File> map) { String[] list = root.list(); for (String name : list) { File f = new File(root, name); if (f.isDirectory() && !f.isHidden()) { index(f, map);/*from w ww .j av a 2 s. co m*/ } else if (f.isFile() && !f.isHidden()) { map.put(FilenameUtils.getExtension(f.getName()).toLowerCase(), f); } } }
From source file:Main.java
/** * deletes all Files and Subfolders in a directory * @param dir target directory/* w w w . j ava2s . c om*/ * @return */ public static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] entries = dir.list(); for (int x = 0; x < entries.length; x++) { File aktFile = new File(dir.getPath(), entries[x]); deleteDir(aktFile); } if (dir.delete()) { return true; } else { return false; } } else { if (dir.delete()) { return true; } else { return false; } } }
From source file:Main.java
/** * Delete every item below the File location * * @param file Location/* w w w. ja va2s. c om*/ */ public static boolean recursiveDelete(File file) { if (file.isDirectory()) { String[] children = file.list(); if (children == null) return false; for (String child : children) { recursiveDelete(new File(file, child)); } } return file.delete(); }
From source file:Main.java
public static void deleteFile(File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { deleteFile(new File(dir, children[i])); }/*w ww . jav a 2s. c o m*/ } dir.delete(); }
From source file:Main.java
public static int deleteBlankPath(String path) { File f = new File(path); if (!f.canWrite()) { return 1; }// w ww .ja v a 2 s. c om if (f.list() != null && f.list().length > 0) { return 2; } if (f.delete()) { return 0; } return 3; }
From source file:Main.java
private static boolean deleteDir(File dir) { if (dir != null && 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; }//from w ww .jav a 2s .co m } } return dir.delete(); }
From source file:Main.java
public static boolean debugRmDir(String dir, boolean deleteDirectory) { File directory = new File(dir); if (directory.isDirectory()) { String[] children = directory.list(); for (String s : children) { if (!debugRmDir(dir + File.separator + s, true)) return false; }//from w w w . ja v a 2s .co m } return !deleteDirectory || directory.delete(); }
From source file:Main.java
/** * Deletes a given folder directory in the form of a {@link File} * //from w w w. j a va 2 s .c om * @param folder The folder to delete. * * @return True if the folder was deleted, false otherwise. */ public static boolean deleteFolder(File folder) { if (folder.isDirectory()) { String[] children = folder.list(); if (children != null) { for (String child : children) { boolean success = deleteFolder(new File(folder, child)); if (!success) return false; } } } return folder.delete(); }