List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
public static void deleteFolder(File folder) { if (folder == null) { return;// w w w . j ava 2 s. c o m } if (folder.isDirectory()) { File[] childs = folder.listFiles(); if (childs != null) { for (File child : childs) { deleteFolder(child); } } } folder.delete(); }
From source file:Main.java
public static void deleteFiles(File file) { try {//from w w w . j ava 2 s. co m if (file.exists()) { if (file.isDirectory()) { File[] childFiles = file.listFiles(); for (File f : childFiles) { deleteFiles(f); } } else { file.delete(); } } } catch (Exception e) { } }
From source file:Utils.java
/** * Empty and delete a folder (and subfolders). * @param folder//from w ww . j av a2 s . co m * folder to empty */ public static void rmdir(final File folder) { // check if folder file is a real folder if (folder.isDirectory()) { File[] list = folder.listFiles(); if (list != null) { for (int i = 0; i < list.length; i++) { File tmpF = list[i]; if (tmpF.isDirectory()) { rmdir(tmpF); } tmpF.delete(); } } if (!folder.delete()) { System.out.println("can't delete folder : " + folder); } } }
From source file:Main.java
public static List<String> getAvailableTitaniumSdkVersions() { String basePath = getTitaniumBaseSdkPath(); if (basePath == null) { return null; }//from w ww.j a va2 s . c o m File baseFolder = new File(basePath); File[] files = baseFolder.listFiles(); if (files != null && files.length > 0) { List<String> versions = new ArrayList<String>(); for (File f : files) { if (f.isDirectory()) { versions.add(f.getName()); } } if (!versions.isEmpty()) { return versions; } } return null; }
From source file:Main.java
/** * Create a list of all the .class files within a directory. * @param path Location from where extract the files. * @param fileNames List where store all the files names. * @param parent Parent path.//w w w .java2s . c o m */ private static void populateFiles(File path, List<String> fileNames, String parent) { if (path.isDirectory()) { for (File newPath : path.listFiles()) { if ("".equals(parent)) { populateFiles(newPath, fileNames, path.getName()); } else { populateFiles(newPath, fileNames, parent + "." + path.getName()); } } } else { String pathName = path.getName(); String classSuffix = ".class"; pathName = pathName.endsWith(classSuffix) ? pathName.substring(0, pathName.length() - classSuffix.length()) : pathName; if ("".equals(parent)) { fileNames.add(pathName); } else { fileNames.add(parent + "." + pathName); } } }
From source file:is.iclt.icenlp.core.utils.FileOperations.java
public static ArrayList<String> getFilePaths(String folderPath) { File rootFolder = new File(folderPath); File[] rootFiles = rootFolder.listFiles(); ArrayList<String> filePaths = new ArrayList<String>(); for (int i = 0; i < rootFiles.length; i++) { String lFolderPath = rootFiles[i].getAbsolutePath(); // l = local if (rootFiles[i].isDirectory()) { filePaths.addAll(getFilePaths(lFolderPath)); } else if (rootFiles[i].isFile()) { filePaths.add(lFolderPath);/*from www. java 2s . c o m*/ } } return filePaths; }
From source file:Main.java
public static void listFilesInDirectory(File dir) throws Exception { String tempfolder = System.getProperty("java.io.tmpdir"); String pathRequiredForFile = null; File[] files = dir.listFiles(); if (files == null) { return;/*from w w w . j a va 2 s .com*/ } for (File f : files) { if (f.isDirectory()) { pathRequiredForFile = f.getName(); listFilesInDirectory(f); } else { System.out.println(f.getName()); File path = new File(tempfolder + "//" + pathRequiredForFile); path.mkdir(); OutputXml(f, path.getAbsolutePath()); } } }
From source file:medcheck.Medcheck.java
private static Drug[] convertToDrugArrayFromXML(File xmlDirectory) { File[] xmlFiles = xmlDirectory.listFiles(); Drug[] drugs = new Drug[xmlFiles.length]; System.out.println(xmlFiles.length); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {//from w ww .j ava 2 s .c o m DocumentBuilder db = dbf.newDocumentBuilder(); for (int i = 0; i < xmlFiles.length; i++) { db.parse(xmlFiles[i]); } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); exit(1); } return drugs; }
From source file:edu.uci.ics.asterix.test.metadata.MetadataTest.java
@AfterClass public static void tearDown() throws Exception { AsterixHyracksIntegrationUtil.deinit(); File outdir = new File(PATH_ACTUAL); File[] files = outdir.listFiles(); if (files == null || files.length == 0) { outdir.delete();//from w ww . j av a 2 s.co m } // clean up the files written by the ASTERIX storage manager for (String d : AsterixHyracksIntegrationUtil.ASTERIX_DATA_DIRS) { TestsUtils.deleteRec(new File(d)); } }
From source file:com.redhat.satellite.search.DeleteIndexes.java
protected static boolean deleteDirectory(File dir) { File[] files = dir.listFiles(); boolean warning = true; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]);/* ww w .j a v a 2 s . c o m*/ } if (files[i].delete()) { log.debug("Deleted: " + files[i].getAbsolutePath()); } else { log.warn("*ERROR* unable to delete: " + files[i].getAbsolutePath()); warning = false; } } if (!dir.delete()) { log.warn("*ERROR* unable to delete: " + dir.getAbsolutePath()); warning = false; } return warning; }