{"record":{"id":"c713c9df7b2900d3","repo":"OrchardCMS/OrchardCore","slug":"cannot-get-directories-with-path-path","errorCode":null,"errorMessage":"Cannot get directories with path '{path}'.","messagePattern":"Cannot get directories with path '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs","lineNumber":167,"sourceCode":"            {\n                return Array.Empty<IFileStoreEntry>().ToAsyncEnumerable();\n            }\n\n            var results = Directory\n                .GetDirectories(physicalPath, \"*\", SearchOption.TopDirectoryOnly)\n                .Select(f =>\n                {\n                    var fileSystemInfo = new PhysicalDirectoryInfo(new DirectoryInfo(f));\n                    var fileRelativePath = f[_fileSystemPath.Length..];\n                    var filePath = this.NormalizePath(fileRelativePath);\n                    return (IFileStoreEntry)new FileSystemStoreEntry(filePath, fileSystemInfo);\n                });\n\n            return results.ToAsyncEnumerable();\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot get directories with path '{path}'.\", ex);\n        }\n    }\n\n    public Task<bool> TryCreateDirectoryAsync(string path)\n    {\n        try\n        {\n            var physicalPath = GetPhysicalPath(path);\n\n            if (File.Exists(physicalPath))\n            {\n                throw new FileStoreException($\"Cannot create directory because the path '{path}' already exists and is a file.\");\n            }\n\n            if (Directory.Exists(physicalPath))\n            {\n                return Task.FromResult(false);\n            }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs#L149-L185","documentation":"FileSystemStore.GetDirectoriesAsync lists only subdirectories under a path and wraps enumeration exceptions in a FileStoreException with this message. A path with no subdirectories returns empty rather than throwing; this error indicates an I/O failure during listing.","triggerScenarios":"Calling IFileStore.GetDirectoriesAsync(path) when Directory.EnumerateDirectories throws: UnauthorizedAccessException on an unreadable subfolder, invalid/too-long path, directory deleted during enumeration, or volume/device errors.","commonSituations":"Media library folder tree broken by ACL changes; enumerating folders on a disconnected network share; invalid characters introduced by user-created folder names; indexer/AV interference.","solutions":["Read the InnerException: UnauthorizedAccessException -> fix ACLs; DirectoryNotFoundException -> path removed; IOException -> lock or device issue.","Grant the app identity list permissions recursively over the storage root.","Sanitize folder names (strip invalid path characters) when creating folders from user input.","Verify the path exists first via GetDirectoryInfoAsync."],"exampleFix":"// before\nvar dirs = fileStore.GetDirectoriesAsync(path);\nawait foreach (var d in dirs) { ... }\n// after\ntry\n{\n    var dirs = fileStore.GetDirectoriesAsync(path);\n    await foreach (var d in dirs) { ... }\n}\ncatch (FileStoreException ex)\n{\n    logger.LogWarning(ex.InnerException, \"Could not list directories under {Path}\", path);\n}","handlingStrategy":"try-catch","validationCode":"if (await fileStore.GetDirectoryInfoAsync(path) == null)\n{\n    return AsyncEnumerable.Empty<IFileStoreEntry>();\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await foreach (var d in fileStore.GetDirectoriesAsync(path)) { /* ... */ }\n}\ncatch (FileStoreException ex)\n{\n    logger.LogError(ex.InnerException, \"Directory listing failed for {Path}\", path);\n}","preventionTips":["Sanitize folder names created from user input","Ensure recursive list permissions on the storage root","Confirm network shares are mounted before serving media","Verify path existence before enumerating"],"tags":["file-system","io","enumeration"],"backgroundTag":"directory-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}