apache/hadoop · error · PathIsNotDirectoryException
Is not a directory
Error message
Is not a directory
What it means
PathIsNotDirectoryException ('Is not a directory') thrown by Rmdir.processPath (Delete.java:208) when 'hadoop fs -rmdir' targets an existing path that is a regular file. rmdir is the POSIX-style 'remove empty directory only' command, so a file argument is rejected before listStatus/delete are attempted.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java:208
"[--ignore-fail-on-non-empty] <dir> ...";
public static final String DESCRIPTION =
"Removes the directory entry specified by each directory argument, " +
"provided it is empty.\n";
private boolean ignoreNonEmpty = false;
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
CommandFormat cf = new CommandFormat(
1, Integer.MAX_VALUE, "-ignore-fail-on-non-empty");
cf.parse(args);
ignoreNonEmpty = cf.getOpt("-ignore-fail-on-non-empty");
}
@Override
protected void processPath(PathData item) throws IOException {
if (!item.stat.isDirectory()) {
throw new PathIsNotDirectoryException(item.toString());
}
if (item.fs.listStatus(item.path).length == 0) {
if (!item.fs.delete(item.path, false)) {
throw new PathIOException(item.toString());
}
} else if (!ignoreNonEmpty) {
throw new PathIsNotEmptyDirectoryException(item.toString());
}
}
}
// delete files from the trash that are older
// than the retention threshold.
static class Expunge extends FsCommand {
private static final String OPTION_FILESYSTEM = "fs";
public static final String NAME = "expunge";
public static final String USAGE =View on GitHub (pinned to 2add963021)
Solutions
- Use 'hadoop fs -rm /data/file.txt' for files
- Guard in scripts: 'hadoop fs -test -d /path && hadoop fs -rmdir /path || hadoop fs -rm /path'
- Use 'hadoop fs -rm -r' when you want both files and directories removed uniformly
Example fix
# before hadoop fs -rmdir /job/_SUCCESS # Is not a directory (_SUCCESS is a file) # after hadoop fs -rm /job/_SUCCESS
Defensive patterns
Strategy: validation
Validate before calling
if (!fs.getFileStatus(path).isDirectory()) {
throw new PathIsNotDirectoryException(path.toString());
} Type guard
static boolean isEmptyableDirectory(FileSystem fs, Path p) throws IOException {
return fs.getFileStatus(p).isDirectory();
} Try / catch
try {
fs.delete(path, false);
} catch (PathIsNotDirectoryException e) {
// it is a file: plain rm/delete is the correct command
} Prevention
- Branch on 'hadoop fs -test -d' before rmdir in scripts
- Use -rm for files, -rmdir strictly for empty directories
- Use rm -r when uniform removal of mixed trees is wanted
When it happens
Trigger: 'hadoop fs -rmdir /data/file.txt'; scripts that assume a path is a directory (e.g. a _SUCCESS-style marker that is actually a file); parameterized cleanup where $DIR sometimes names a file.
Common situations: Marker files confused with directories; porting 'rm -d' semantics; cleanup jobs iterating over a mix of files and dirs with a single command.
Related errors
- Directory is not empty
- Is not a directory
- Illegal option {}
- Not enough arguments: expected {} but got {}
- Too many arguments: expected {} but got {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/efba0496f1a8a52e.
Report an issue: GitHub.