MuntashirAkon/AppManager · error · IOException
Directory
Error message
Directory
What it means
If DocumentFile.createDirectory(lastSegment) returns null (the provider failed to create the directory), createDirectories() throws IOException("Directory<parentUri>/<lastSegment> could not be created."). Note the message has no space after "Directory" — a cosmetic bug. It signals the storage backend refused or failed the creation.
Source
Thrown at app/src/main/java/io/github/muntashirakon/io/PathImpl.java:453
if (dirNames.length == 0) {
throw new IllegalArgumentException("Display name is empty");
}
for (String name : dirNames) {
if (name.equals("..")) {
throw new IOException("Could not create directories in the parent directory.");
}
}
DocumentFile file = createArbitraryDirectories(documentFile, dirNames, dirNames.length - 1);
// Special case for the last segment
String lastSegment = dirNames[dirNames.length - 1];
Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(file.getUri(), lastSegment));
DocumentFile t = fsRoot != null ? fsRoot.documentFile : file.findFile(lastSegment);
if (t != null) {
throw new IOException(t.getUri() + " already exists.");
}
t = file.createDirectory(lastSegment);
if (t == null) {
throw new IOException("Directory" + file.getUri() + File.separator + lastSegment + " could not be created.");
}
return new PathImpl(context, t);
}
@Nullable
public Path getParent() {
DocumentFile file = getRealDocumentFile(documentFile).getParentFile();
return file == null ? null : new PathImpl(context, file);
}
public boolean hasFile(@NonNull String displayName) {
return findFileInternal(documentFile, displayName) != null;
}
@NonNull
public Path findFile(@NonNull String displayName) throws FileNotFoundException {
DocumentFile nextPath = findFileInternal(documentFile, displayName);
if (nextPath == null) {View on GitHub (pinned to 0152f468fc)
Solutions
- Verify the name contains only provider-safe characters (no slashes, control chars, or reserved names).
- Check available storage and that the volume is writable/mounted before creating.
- Re-acquire SAF permissions (ACTION_OPEN_DOCUMENT_TREE) and confirm canWrite() on the parent.
- Retry against a different parent or use MediaStore/app-specific storage if SAF keeps failing.
Example fix
// before
path.createDirectories(dirName); // IOException: Directory...could not be created.
// after
DocumentFile parent = getRealDocumentFile(path);
if (parent != null && parent.canWrite()) {
path.createDirectories(dirName);
} Defensive patterns
Strategy: try-catch
Validate before calling
DocumentFile parent = getRealDocumentFile(path); boolean writable = parent != null && parent.canWrite() && parent.isDirectory();
Try / catch
try {
return path.createDirectories(name);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("could not be created")) {
throw new IOException("Storage unwritable or name rejected: " + name, e);
}
throw e;
} Prevention
- Check canWrite() and storage space first
- Keep SAF tree grants alive (persistable permissions)
- Avoid provider-unsafe characters in names
When it happens
Trigger: file.createDirectory() returns null because the DocumentsProvider rejected the create: invalid characters in the name, name too long, read-only/external storage, or provider error.
Common situations: Writing to an SD card that is read-only or unmounted; directory names with characters the provider disallows; exhausted storage; SAF grants revoked so the tree is no longer writable.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Current file is not a directory.
- Could not create directory named ${displayName}
- Could not create
- Couldn't find any writable Obb dir
- Could not delete the selected backups
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/f1044fe88a512ccb.
Report an issue: GitHub.