
# 删除HDFS指定目录
#### 功能简介
删除HDFS上某个指定目录。
![](https://support.huaweicloud.com/devg3-mrs/public_sys-resources/note_3.0-zh-cn.png)
被删除的目录会被直接删除，且无法恢复。所以，执行删除操作需谨慎。
#### 代码样例
如下是删除文件的代码片段，详细代码请参考com.huawei.bigdata.hdfs.examples中的HdfsExample类。
```
/**
 * 删除目录
 *
 * @throws java.io.IOException
 */
private void rmdir() throws IOException {
    Path destPath = new Path(DEST_PATH);
    if (!deletePath(destPath)) {
        LOG.error("failed to delete destPath " + DEST_PATH);
        return;
    }
    LOG.info("success to delete path " + DEST_PATH);
}
/**
 * delete file path
 *
 * @param filePath
 * @return
 * @throws java.io.IOException
 */
private boolean deletePath(final Path filePath) throws IOException {
    if (!fSystem.exists(filePath)) {
        return false;
    }
    // fSystem.delete(filePath, true);
    return fSystem.delete(filePath, true);
}
```
