Deletes a directory and optionally removes the parent directory if it becomes empty.

@param path
@param cleanParent
@return
@throws IOException
11272
protected boolean deleteDirectory(Path path, boolean cleanParent) throws IOException {
        boolean pathExists = deleteIfExistsRecursively(path);
        if(pathExists && cleanParent) {
            cleanEmptyParentDirectory(path.getParent());
            return true;
        }
        return false;
    }
381716
@Override
    public Node delete(ArchivePath path) {
        Validate.notNull(path, "No path was specified");
        ArchivePath safePath = path;

        NodeImpl node = content.get(safePath);
        if (node == null) {
            if (path.get().endsWith("/")) {
                safePath = ArchivePaths.create(path.get().substring(0, path.get().length() - 1));
                node = content.get(safePath);
            }
            if (node == null) {
                return null;
            }
        }

        return removeNodeRecursively(node, safePath);
    }
968789
public static void deleteIfExists(FileSystem fs, Path path, boolean recursive) throws IOException {
    if (fs.exists(path)) {
      deletePath(fs, path, recursive);
    }
  }
840258
@SuppressWarnings("ResultOfMethodCallIgnored")
    static private void deleteDirectory(File path) {
        if (path.exists()) {
            //noinspection ConstantConditions
            for (File f : path.listFiles()) {
                if (f.isDirectory()) {
                    deleteDirectory(f);
                }
                f.delete();
            }
            path.delete();
        }
    }
1152117
public static void delete(String path) throws IOException {
    if (!Files.deleteIfExists(Paths.get(path))) {
      throw new IOException("Failed to delete " + path);
    }
  }
1011007
@Nullable
  protected String getParentPath(String path) {
    // Root does not have a parent.
    if (isRoot(path)) {
      return null;
    }
    int separatorIndex = path.lastIndexOf(PATH_SEPARATOR);
    if (separatorIndex < 0) {
      return null;
    }
    return path.substring(0, separatorIndex);
  }
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;
				}
			}
		});
	}
1287453
function _deleteAtPath(treeData, path) {
        var objectPath = _filePathToObjectPath(treeData, path);

        if (!objectPath) {
            return;
        }

        var originalName = _.last(objectPath);

        // Back up to the parent directory
        objectPath.pop();

        treeData = treeData.updateIn(objectPath, function (directory) {
            directory = directory.delete(originalName);
            return directory;
        });

        return treeData;
    }
866689
static void fullyDelete(String dir, Configuration conf) throws IOException {
    if (dir != null) {
      Path tmp = new Path(dir);
      tmp.getFileSystem(conf).delete(tmp, true);
    }
  }
2575
public static void ensureParentDirectoryExists(File f) throws IOException {
    final File parent = f.getParentFile();
    if (parent != null) {
      java.nio.file.Files.createDirectories(parent.toPath());
    }
  }
1297052
static public void recursiveDeleteDirectory(FTPClient ftpClient, String path) throws IOException {

        logger.info("Delete directory: {}", path);

        FTPFile[] ftpFiles = ftpClient.listFiles(path);
        logger.debug("Number of files that will be deleted: {}", ftpFiles.length);

        for (FTPFile ftpFile : ftpFiles){
            String filename = path + "/" + ftpFile.getName();
            if (ftpFile.getType() == FTPFile.FILE_TYPE) {
                boolean deleted = ftpClient.deleteFile(filename);
                logger.debug("Deleted {}? {}", filename, deleted);
            } else {
                recursiveDeleteDirectory(ftpClient, filename);
            }
        }

        boolean dirDeleted = ftpClient.deleteFile(path);
        logger.debug("Directory {} deleted: {}", path, dirDeleted);
    }
1264625
public static void deleteDirectory(Path dir) throws IOException {
		if(dir == null || !Files.exists(dir))
			return;
		Files.walkFileTree(dir, 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) {
	                throw e;
	            }
	            Files.delete(dir);
	            return FileVisitResult.CONTINUE;
	        }
	    });
	}
1053883
public Tree clear(String path) {
		Tree child = getChild(path, false);
		if (child == null) {
			child = putMap(path);
		} else {
			child.clear();
		}
		return child;
	}
1281832
private void createParent(Path path) throws IOException {
      Path parent = path.getParent();
      if (parent != null) {
          String key = pathToKey(makeAbsolute(parent));
          if (key.length() > 0) {
              store.storeEmptyFile(key + FOLDER_SUFFIX);
          }
      }
  }
463099
protected boolean checkParentDirs(String path, boolean create_if_absent) throws IOException {
        String[] components=Util.components(path, File.separator);
        if(components == null)
            return false;
        if(components.length == 1) // no parent directories to create, e.g. "data.txt"
            return true;

        StringBuilder sb=new StringBuilder();
        boolean first=true;

        for(int i=0; i < components.length-1; i++) {
            String tmp=components[i];
            if(!tmp.equals(File.separator)) {
                if(first)
                    first=false;
                else
                    sb.append(File.separator);
            }
            sb.append(tmp);
            String comp=sb.toString();
            if(exists(comp)) {
                if(isFile(comp))
                    throw new IOException("cannot create " + path + " as component " + comp + " is a file");
            }
            else {
                if(create_if_absent)
                    cache.put(comp, new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0);
                else
                    return false;
            }
        }
        return true;
    }
734433
public static void deleteDir(Path dir) throws IOException {
		Validate.isTrue(isDirExists(dir), "%s is not exist or not a dir", dir);

		// 后序遍历，先删掉子目录中的文件/目录
		Files.walkFileTree(dir, deleteFileVisitor);
	}
1350421
private static void deleteDirectoryOnExit(File directory) throws IOException {
    if (!directory.exists()) {
      return;
    }

    directory.deleteOnExit();
    if (!isSymlink(directory)) {
      cleanDirectoryOnExit(directory);
    }
  }