{"record":{"id":"5f8bd98d0d1b2b87","repo":"MuntashirAkon/AppManager","slug":"could-not-create-directory-named","errorCode":null,"errorMessage":"Could not create directory named ","messagePattern":"Could not create directory named ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":533,"sourceCode":"        }\n        if (displayName.indexOf(File.separatorChar) != -1) {\n            throw new IllegalArgumentException(\"Display name contains file separator.\");\n        }\n        DocumentFile documentFile = getRealDocumentFile(this.documentFile);\n        if (!documentFile.isDirectory()) {\n            throw new IOException(\"Current file is not a directory.\");\n        }\n        Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(documentFile.getUri(), displayName));\n        if (fsRoot != null) return fsRoot;\n        DocumentFile file = documentFile.findFile(displayName);\n        if (file != null) {\n            if (!file.isDirectory()) {\n                throw new IOException(\"Existing file is not a directory\");\n            }\n            return new PathImpl(context, file);\n        }\n        file = documentFile.createDirectory(displayName);\n        if (file == null) throw new IOException(\"Could not create directory named \" + displayName);\n        return new PathImpl(context, file);\n    }\n\n    @NonNull\n    public PathAttributes getAttributes() throws IOException {\n        if (documentFile instanceof ExtendedRawDocumentFile) {\n            return PathAttributesImpl.fromFile((ExtendedRawDocumentFile) documentFile);\n        }\n        if (documentFile instanceof VirtualDocumentFile) {\n            return PathAttributesImpl.fromVirtual((VirtualDocumentFile) documentFile);\n        }\n        return PathAttributesImpl.fromSaf(context, documentFile);\n    }\n\n    @CheckResult\n    public boolean exists() {\n        return getRealDocumentFile(documentFile).exists();\n    }","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L515-L551","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify write permission on the parent (path.canWrite()) and re-grant/persist SAF tree permissions (takePersistableUriPermission)","Check that the underlying storage is mounted, writable, and has free space","Inspect the displayName for provider-invalid characters and retry with a sanitized name"],"exampleFix":"// before\npath.findOrCreateDirectory(\"cache\"); // throws if provider can't create\n// after\ntry {\n    Path dir = path.findOrCreateDirectory(\"cache\");\n} catch (IOException e) {\n    if (!path.canWrite()) throw new IOException(\"No write access to \" + path.getUri(), e);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!path.canWrite()) throw new IOException(\"No write access: \" + path.getUri());","typeGuard":null,"tryCatchPattern":"try {\n    Path dir = path.findOrCreateDirectory(name);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Could not create directory named\")) {\n        // check permissions/storage, re-grant SAF, or retry later\n    } else throw e;\n}","preventionTips":["Persist SAF tree permissions with takePersistableUriPermission","Verify storage is mounted, writable, and has free space","Check canWrite() on the parent before create attempts"],"tags":["io","android","documentfile","saf"],"backgroundTag":"file-write-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}