Deletes a directory recursively.

@param pFile the file to delete
@return {@code true} if the file was deleted sucessfully
@throws IOException if an i/o error occurs during delete.
483400
private static boolean deleteDir(final File pFile) throws IOException {
        // Recusively delete all files/subfolders
        // Deletes the files using visitor pattern, to avoid allocating
        // a file array, which may throw OutOfMemoryExceptions for
        // large directories/in low memory situations
        class DeleteFilesVisitor implements Visitor<File> {
            private int failedCount = 0;
            private IOException exception = null;

            public void visit(final File pFile) {
                try {
                    if (!delete(pFile, true)) {
                        failedCount++;
                    }
                }
                catch (IOException e) {
                    failedCount++;
                    if (exception == null) {
                        exception = e;
                    }
                }
            }

            boolean succeeded() throws IOException {
                if (exception != null) {
                    throw exception;
                }
                return failedCount == 0;
            }
        }
        DeleteFilesVisitor fileDeleter = new DeleteFilesVisitor();
        visitFiles(pFile, null, fileDeleter);

        // If any of the deletes above failed, this will fail (or return false)
        return fileDeleter.succeeded() && pFile.delete();
    }
489436
public static void deleteFilesRecursively( File... files ) throws IOException {

		if( files == null )
			return;

		List<File> filesToDelete = new ArrayList<> ();
		filesToDelete.addAll( Arrays.asList( files ));
		while( ! filesToDelete.isEmpty()) {
			File currentFile = filesToDelete.remove( 0 );
			if( currentFile == null
					|| ! currentFile.exists())
				continue;

			// Non-empty directory: add sub-files and reinsert the current directory after
			File[] subFiles = currentFile.listFiles();
			if( subFiles != null && subFiles.length > 0 ) {
				filesToDelete.add( 0, currentFile );
				filesToDelete.addAll( 0, Arrays.asList( subFiles ));
			}

			// Existing file or empty directory => delete it
			else if( ! currentFile.delete())
				throw new IOException( currentFile.getAbsolutePath() + " could not be deleted." );
		}
	}
145839
public static void recursivelyDeleteDirectory(File directory) throws IOException {
    if (!directory.exists()) {
      return;
    }
    checkArgument(directory.isDirectory(), "Cannot recursively delete a non-directory");
    walkFileTree(directory.toPath(), new DeletionFileVisitor());
  }
518027
public static void deleteDirRecursive(File dir) throws IOException {
        File failed = deleteDirRecursiveInternal(dir, true);
        if (failed != null) {
            throw new IOException("Could not delete file: " + failed.getPath());
        }
    }
601042
public static void removeDirectory(File dir) throws IOException
   {
      if (dir.isDirectory())
      {
         for (File subFile : dir.listFiles())
         {
            removeDirectory(subFile);
         }

         if (!dir.delete())
         {
            throw new IOException("Can't remove folder : " + dir.getCanonicalPath());
         }
      }
      else
      {
         if (!dir.delete())
         {
            throw new IOException("Can't remove file : " + dir.getCanonicalPath());
         }
      }
   }
1179281
public void deleteFile(JimfsPath path, DeleteMode deleteMode) throws IOException {
    store.writeLock().lock();
    try {
      DirectoryEntry entry = lookUp(path, Options.NOFOLLOW_LINKS).requireExists(path);
      delete(entry, deleteMode, path);
    } finally {
      store.writeLock().unlock();
    }
  }
1028319
public static boolean delete(File f) {
		if (f == null || !f.exists()) return true;
		if (f.isDirectory()) {
			File[] subFiles = f.listFiles();
			if (subFiles != null) {
				for (File sf : subFiles) {
					IOUtil.delete(sf);
				}
			}
		}
		return f.delete();
	}
591174
public static boolean deleteRecursive(final File file) {
		boolean result = true;
		if (file.isDirectory()) {
			for (final File inner : file.listFiles()) {
				result &= deleteRecursive(inner);
			}
		}
		return result & file.delete();
	}
305507
private boolean delete(final File f) throws IOException {

		if (f.isDirectory()) {

			final File[] files = f.listFiles();
			for (int i = 0; i < files.length; i++) {
				final boolean del = delete(files[i]);
				if (del == false) {
					return false;
				}
			}

		} else {
			return f.delete();
		}

		// Now directory is empty
		return f.delete();
	}
709909
public static boolean deleteOrDie(@Nonnull final String file) throws IOException {
        // this returns true if the file was actually deleted
        // and false for 2 cases:
        //   1. file did not exist to start with
        //   2. File.delete() failed at some point for some reason
        // so we disambiguate the 'false' case below by checking for file existence
        final boolean fileWasDeleted = delete(file);

        if (fileWasDeleted) {
            // file was definitely deleted
            return true;
        } else {
            final File fileObj = new File(file);
            if (fileObj.exists()) {
                throw new IOException("File still exists after erasure, cannot write object to file: " + file);
            }

            // file was not deleted, because it does not exist
            return false;
        }
    }
977797
public static void recursiveDelete(Path directory) throws IOException   {

        try {
            Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws java.io.IOException {
                    try {
                        Files.delete(file);
                    } catch (NoSuchFileException ignore) {}
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, java.io.IOException exc) throws java.io.IOException {
                    try{
                        Files.delete(dir);
                    }catch (NoSuchFileException ignore){}
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (NoSuchFileException ignore) {}

    }
1094606
public boolean deleteStructure(String pdbId) throws IOException{
		boolean deleted = false;
		// Force getLocalFile to check in obsolete locations
		ObsoleteBehavior obsolete = getObsoleteBehavior();
		setObsoleteBehavior(ObsoleteBehavior.FETCH_OBSOLETE);

		try {
			File existing = getLocalFile(pdbId);
			while(existing != null) {
				assert(existing.exists()); // should exist unless concurrency problems

				if( getFetchBehavior() == FetchBehavior.LOCAL_ONLY) {
					throw new RuntimeException("Refusing to delete from LOCAL_ONLY directory");
				}

				// delete file
				boolean success = existing.delete();
				if(success) {
					logger.debug("Deleting "+existing.getAbsolutePath());
				}
				deleted = deleted || success;

				// delete parent if empty
				File parent = existing.getParentFile();
				if(parent != null) {
					success = parent.delete();
					if(success) {
						logger.debug("Deleting "+parent.getAbsolutePath());
					}
				}

				existing = getLocalFile(pdbId);
			}
			return deleted;

		} finally {
			setObsoleteBehavior(obsolete);
		}
	}
61060
public static boolean delete(File f) throws IOException
	{
		assert (f.exists());

		if (f.isDirectory())
		{
			FileUtils.deleteDirectory(f);
			return true;
		}
		else
		{
			return f.delete();
		}
	}
628879
public static void deleteRecursive(Path start, boolean deleteStart) throws IOException {
		Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
				Files.delete(file);
				return FileVisitResult.CONTINUE;
			}
			@Override
			public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
				if (e == null) {
					if (deleteStart || !Files.isSameFile(dir, start)) {
						Files.delete(dir);
					}
					return FileVisitResult.CONTINUE;
				} else {
					// directory iteration failed
					throw e;
				}
			}
		});
	}
851732
public static boolean deleteDirectoryTree( File dir )
    {
        File[] files = dir.listFiles();
        if (files == null) files = new File[0];
        for (File file : files)
        {
            deleteDirectoryTree( file );
        }
        return dir.delete();
    }
844684
public static boolean clearDirectory(File directory) {
    if (directory.isDirectory()) {
      for (File file : directory.listFiles()) {
        if (!deleteRecursive(file)) {
          return false;
        }
      }
    }
    return true;
  }
899475
public static boolean delete(File d) {
        if (null == d || !d.exists())
            return true; // by definition

        if (d.isDirectory()) {
            File[] files = d.listFiles(); // and directories
            if (null != files) {
                for (File f : files) {
                    if (f.isDirectory()) {
                        delete(f);
                    } else {
                        f.delete();
                    }
                }
            }
        }
        return d.delete();
    }