{"record":{"id":"16b122dcdf299c8b","repo":"peass-ng/PEASS-ng","slug":"resources-cannot-create-directory","errorCode":null,"errorMessage":"Resources.Cannot_Create_Directory","messagePattern":"Resources\\.Cannot_Create_Directory","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateDirectoryCore.cs","lineNumber":182,"sourceCode":"            // We are not always interested in a new DirectoryInfo instance.\n\n            return returnNull ? null : new DirectoryInfo(transaction, longPath, PathFormat.LongFullPath);\n         }\n      }\n\n\n      private static Stack<string> ConstructFullPath(KernelTransaction transaction, string path)\n      {\n         var longPathPrefix = Path.IsUncPathCore(path, false, false) ? Path.LongPathUncPrefix : Path.LongPathPrefix;\n         path = Path.GetRegularPathCore(path, GetFullPathOptions.None, false);\n\n         var length = path.Length;\n         if (length >= 2 && Path.IsDVsc(path[length - 1], false))\n            --length;\n\n         var rootLength = Path.GetRootLength(path, false);\n         if (length == 2 && Path.IsDVsc(path[1], false))\n            throw new ArgumentException(Resources.Cannot_Create_Directory, \"path\");\n\n\n         // Check if directories are missing.\n         var list = new Stack<string>(100);\n\n         if (length > rootLength)\n         {\n            for (var index = length - 1; index >= rootLength; --index)\n            {\n               var path1 = path.Substring(0, index + 1);\n               var path2 = longPathPrefix + path1.TrimStart('\\\\');\n\n               if (!File.ExistsCore(transaction, true, path2, PathFormat.LongFullPath))\n                  list.Push(path2);\n\n               while (index > rootLength && !Path.IsDVsc(path[index], false))\n                  --index;\n            }","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateDirectoryCore.cs#L164-L200","documentation":"AlphaFS's ConstructFullPath helper validates that a path can serve as a directory root. When the trimmed path is exactly a drive-like two characters ('C:' with a drive-letter/vertical-slash character at index 1), it throws ArgumentException(Resources.Cannot_Create_Directory, 'path') because creating a directory at a bare drive specifier is meaningless. This surfaces when CreateDirectoryCore tries to construct the full path of directories to create.","triggerScenarios":"Calling Directory.CreateDirectory with a path that resolves to just a drive specifier like \"C:\" or \"C:\" with trailing separator trimmed away; the check triggers when path.Length==2 and path[1] is a drive/volume separator character.","commonSituations":"Config value holding just a drive letter (e.g. backup target \"D:\"); string splitting that cut a path down to the drive; Path.GetPathRoot result passed directly as the directory to create; user input \"C:\" accepted by a UI.","solutions":["Pass a real directory path with at least one folder component, e.g. \"C:\\\\Temp\" instead of \"C:\".","If you need the drive root, use \"C:\\\\\" (drive + separator) — the guard only rejects the bare 2-char form — or better, create a named folder on it.","If the input is a root from Path.GetPathRoot and creation is pointless, short-circuit: skip CreateDirectory when path equals its own root.","Append a default subdirectory when the resolved path has no folder part: if (Path.GetDirectoryName(p) == null) p = Path.Combine(p, \"app\")."],"exampleFix":"// before\nDirectory.CreateDirectory(Path.GetPathRoot(target)); // \"C:\"\n// after\nvar root = Path.GetPathRoot(target);\nvar dir = Path.Combine(root, \"myapp\");\nDirectory.CreateDirectory(dir);","handlingStrategy":"validation","validationCode":"static void EnsureNotBareDrive(string path)\n{\n    if (!string.IsNullOrEmpty(path) && path.Length == 2 && path[1] == ':')\n        throw new ArgumentException($\"'{path}' is a bare drive; provide a folder path\");\n}\nEnsureNotBareDrive(path);\nDirectory.CreateDirectory(path);","typeGuard":"static bool IsBareDrivePath(string p) =>\n    p != null && p.Length == 2 && char.IsLetter(p[0]) && p[1] == ':';","tryCatchPattern":"try\n{\n    Directory.CreateDirectory(path);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"path\")\n{\n    // bare drive specifier like \"C:\" cannot be created\n    logger.LogWarning(\"Refusing to create directory at bare drive: {Path}\", path);\n}","preventionTips":["Check whether the intended directory equals Path.GetPathRoot and skip creation in that case.","Ensure config values for directories always include a folder component (\"D:\\\\data\", not \"D:\").","Beware string truncation/splitting that can reduce a path to its drive.","After trimming trailing separators, re-validate the path still has a leaf."],"tags":["argumentexception","path-validation","drive-root","alphafs","dotnet"],"backgroundTag":"invalid-directory-path","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}