{"record":{"id":"ea6010f5c82e5b4b","repo":"peass-ng/PEASS-ng","slug":"the-target-directory-is-a-file-not-a-directory","errorCode":null,"errorMessage":"The target directory is a file, not a directory: [{0}]","messagePattern":"The target directory is a file, not a directory: \\[(.+?)\\]","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.DeleteEmptySubdirectoriesCore.cs","lineNumber":71,"sourceCode":"         {\n            if (pathFormat == PathFormat.RelativePath)\n               Path.CheckSupportedPathFormat(path, true, true);\n\n            if (!File.ExistsCore(transaction, true, path, pathFormat))\n               NativeError.ThrowException(Win32Errors.ERROR_PATH_NOT_FOUND, path);\n\n            fsEntryInfo = File.GetFileSystemEntryInfoCore(transaction, true, Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck), false, pathFormat);\n\n            if (null == fsEntryInfo)\n               return;\n         }\n\n         #endregion // Setup\n\n\n         // Ensure path is a directory.\n         if (!fsEntryInfo.IsDirectory)\n            throw new IOException(string.Format(CultureInfo.InvariantCulture, Resources.Target_Directory_Is_A_File, fsEntryInfo.LongFullPath));\n\n\n         var dirs = new Stack<string>(1000);\n         dirs.Push(fsEntryInfo.LongFullPath);\n\n         while (dirs.Count > 0)\n         {\n            foreach (var fsei in EnumerateFileSystemEntryInfosCore<FileSystemEntryInfo>(true, transaction, dirs.Pop(), Path.WildcardStarMatchAll, null, DirectoryEnumerationOptions.ContinueOnException, null, PathFormat.LongFullPath))\n            {\n               // Ensure the directory is empty.\n               if (IsEmptyCore(transaction, fsei.LongFullPath, pathFormat))\n                  DeleteDirectoryCore(transaction, fsei, null, false, ignoreReadOnly, true, PathFormat.LongFullPath);\n\n               else if (recursive)\n                  dirs.Push(fsei.LongFullPath);\n            }\n         }\n      }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.DeleteEmptySubdirectoriesCore.cs#L53-L89","documentation":"DeleteEmptySubdirectoriesCore throws IOException with message 'The target directory is a file, not a directory: [{0}]' when the fsEntryInfo resolved from the given path reports IsDirectory == false. DeleteEmptySubdirectories only makes sense on directories, so AlphaFS fails fast with this explicit message rather than letting the native layer return a generic error.","triggerScenarios":"Calling Directory.DeleteEmptySubdirectories / DeleteEmptySubdirectoriesTransacted with a path that points to a regular file; a reparse point/symlink that resolves to a file; stale path captured before the directory was replaced by a file.","commonSituations":"Automated cleanup jobs iterating a list of paths where some entries are files; configuration/user input supplying a file path; a race where another process swapped the directory for a file between enumeration and the call.","solutions":["Check Directory.Exists(path) and that it is not a file (File.Exists) before calling.","Inspect FileSystemEntryInfo.IsDirectory via File.GetFileSystemEntryInfo before invoking.","Filter your path list to directories only using Directory.GetFileSystemEntries / attributes.","Catch IOException and log/skip non-directory entries in batch cleanup loops."],"exampleFix":"// before\nDirectory.DeleteEmptySubdirectories(p); // p may be a file\n// after\nvar info = File.GetFileSystemEntryInfo(p);\nif (info != null && info.IsDirectory)\n    Directory.DeleteEmptySubdirectories(p);","handlingStrategy":"validation","validationCode":"var info = File.GetFileSystemEntryInfo(path);\nif (info == null || !info.IsDirectory)\n    throw new InvalidOperationException($\"{path} is not a directory\");","typeGuard":"bool IsDirectoryEntry(FileSystemEntryInfo e) => e != null && e.IsDirectory;","tryCatchPattern":"try { Directory.DeleteEmptySubdirectories(path); }\ncatch (IOException ex) when (ex.Message.Contains(\"is a file\")) { logger.LogWarning(\"Skipping non-directory {Path}\", path); }","preventionTips":["Filter path lists to directories before batch cleanup","Check IsDirectory on FileSystemEntryInfo before directory-only operations","Handle entries being replaced by files concurrently (re-check late)","Log and skip rather than abort whole cleanup runs on type mismatches"],"tags":["windows","filesystem","wrong-item-type","cleanup"],"backgroundTag":"target-is-file-not-directory","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}