MuntashirAkon/AppManager · error · IOException

Could not create directory named

Error message

Could not create directory named 

What it means

After confirming no existing child matches the name, findOrCreateDirectory() calls documentFile.createDirectory(displayName); if the provider returns null (creation failed silently, as DocumentFile APIs do), the method throws IOException("Could not create directory named <name>"). The provider refused or failed to create the directory without throwing itself.

Source

Thrown at app/src/main/java/io/github/muntashirakon/io/PathImpl.java:533

        }
        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.");
        }
        Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(documentFile.getUri(), displayName));
        if (fsRoot != null) return fsRoot;
        DocumentFile file = documentFile.findFile(displayName);
        if (file != null) {
            if (!file.isDirectory()) {
                throw new IOException("Existing file is not a directory");
            }
            return new PathImpl(context, file);
        }
        file = documentFile.createDirectory(displayName);
        if (file == null) throw new IOException("Could not create directory named " + displayName);
        return new PathImpl(context, file);
    }

    @NonNull
    public PathAttributes getAttributes() throws IOException {
        if (documentFile instanceof ExtendedRawDocumentFile) {
            return PathAttributesImpl.fromFile((ExtendedRawDocumentFile) documentFile);
        }
        if (documentFile instanceof VirtualDocumentFile) {
            return PathAttributesImpl.fromVirtual((VirtualDocumentFile) documentFile);
        }
        return PathAttributesImpl.fromSaf(context, documentFile);
    }

    @CheckResult
    public boolean exists() {
        return getRealDocumentFile(documentFile).exists();
    }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Verify write permission on the parent (path.canWrite()) and re-grant/persist SAF tree permissions (takePersistableUriPermission)
  2. Check that the underlying storage is mounted, writable, and has free space
  3. Inspect the displayName for provider-invalid characters and retry with a sanitized name

Example fix

// before
path.findOrCreateDirectory("cache"); // throws if provider can't create
// after
try {
    Path dir = path.findOrCreateDirectory("cache");
} catch (IOException e) {
    if (!path.canWrite()) throw new IOException("No write access to " + path.getUri(), e);
    throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!path.canWrite()) throw new IOException("No write access: " + path.getUri());

Try / catch

try {
    Path dir = path.findOrCreateDirectory(name);
} catch (IOException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Could not create directory named")) {
        // check permissions/storage, re-grant SAF, or retry later
    } else throw e;
}

Prevention

When it happens

Trigger: documentFile.createDirectory() returns null — typically due to storage permission issues, read-only or full storage, SAF provider restrictions on the remote volume, or an invalid/unsupported name for that provider.

Common situations: Writing to external SD cards via SAF without persisted URI permissions, custom storage (saf/ftp roots in this library) being offline or read-only, or names the provider rejects.

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


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/5f8bd98d0d1b2b87. Report an issue: GitHub.