MuntashirAkon/AppManager · error · IOException
Could not create directory named ${displayName}
Error message
Could not create directory named ${displayName} What it means
After passing the is-directory check, createNewDirectory delegates to DocumentFile.createDirectory(displayName). SAF returns null when the underlying DocumentsProvider refuses or fails to create the folder, and the library converts that null into this IOException. The provider's reason (permission, existing name, storage full) is not surfaced.
Source
Thrown at app/src/main/java/io/github/muntashirakon/io/PathImpl.java:386
return createFileAsDirectChild(context, documentFile, displayName, mimeType);
}
@NonNull
public Path createNewDirectory(@NonNull String displayName) throws IOException {
displayName = Paths.sanitize(displayName, true);
if (displayName == null) {
throw new IOException("Empty display name.");
}
if (displayName.indexOf(File.separatorChar) != -1) {
throw new IllegalArgumentException("Display name contains file separator.");
}
DocumentFile documentFile = getRealDocumentFile(this.documentFile);
if (!documentFile.isDirectory()) {
throw new IOException("Current file is not a directory.");
}
checkVfs(Paths.appendPathSegment(documentFile.getUri(), displayName));
DocumentFile file = documentFile.createDirectory(displayName);
if (file == null) throw new IOException("Could not create directory named " + displayName);
return new PathImpl(context, file);
}
@NonNull
public Path createNewArbitraryFile(@NonNull String displayName, @Nullable String mimeType) throws IOException {
displayName = Paths.sanitize(displayName, true);
if (displayName == null) {
throw new IOException("Empty display name.");
}
String[] names = displayName.split(File.separator);
if (names.length == 0) {
throw new IllegalArgumentException("Display name is empty.");
}
for (String name : names) {
if (name.equals("..")) {
throw new IOException("Could not create directories in the parent directory.");
}
}View on GitHub (pinned to 0152f468fc)
Solutions
- Verify the app can write to the tree (try creating a throwaway file first, or check canWrite() on the DocumentFile)
- Re-request the tree URI with Intent.FLAG_GRANT_READ/WRITE and ACTION_OPEN_DOCUMENT_TREE for a writable grant
- Check device storage/free space and that the external volume is mounted
- Catch the IOException and show a user-facing 'could not create folder' message with the target name
Example fix
// before
parent.createNewDirectory(name); // may fail silently in provider
// after
if (!parent.toDocumentFile().canWrite()) {
requestWritableTreeAccess(); // re-launch ACTION_OPEN_DOCUMENT_TREE
}
parent.createNewDirectory(name); Defensive patterns
Strategy: try-catch
Validate before calling
if (!parentDoc.canWrite()) { requestWritableTreeAccess(); } Try / catch
try {
Path dir = parent.createNewDirectory(name);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Could not create directory named")) {
showCreateFailed(context, name); // provider refused; check grants/storage
} else throw e;
} Prevention
- Request the tree URI with both read and write grants and persist them
- Test write access (canWrite()) before batch folder creation
- Check storage free space and volume mount state on external/SD storage
- Don't rely on read-only tree URIs (e.g. downloads provider) for creation
When it happens
Trigger: Calling createNewDirectory when the provider cannot create the folder: read-only tree URI (e.g. USB OTG without write permission), provider crash, name colliding in an unexpected way, or external storage unavailable.
Common situations: Working with external SD-card trees on Android without SAF write grants; cloud DocumentsProviders being offline; storage full; creating directories inside a tree obtained with a read-only intent.
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.
- Directory
- Could not delete the selected backups
- An uninstallation was necessary but couldn't perform it.
- Could not create package staging directory
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/ea508350be5e7218.
Report an issue: GitHub.