Deze pagina is nog niet beschikbaar in uw eigen taal. We werken er hard aan om meer taalversies toe te voegen. Bedankt voor uw steun.

On this page

Deleting Directories

Updated on 2022-09-14 GMT+08:00

Function

Delete a specified directory from the HDFS.

NOTE:

Files in the deleted directory will be stored in the Trash/Current folder of the directory of the current user. In the event of mis-deletion, you can restore the folder from the directory.

Example Codes

The following is a code snippet of file deletion. For complete codes, see the HdfsExample class in com.huawei.bigdata.hdfs.examples.

 
/**
 * delete the directory 
 *
 * @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);
}
Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback