{"record":{"id":"153fcbc60d264d55","repo":"peass-ng/PEASS-ng","slug":"error-file-read-only","errorCode":"ERROR_FILE_READ_ONLY","errorMessage":"({145}) The file is read-only: [{pathLp}]","messagePattern":"\\((.+?)\\) The file is read-only: \\[(.+?)\\]","errorType":"exception","errorClass":"DirectoryReadOnlyException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.DeleteDirectoryNative.cs","lineNumber":106,"sourceCode":"                        attributes = attrs.dwFileAttributes;\n                  }\n\n\n                  if (File.IsReadOnlyOrHidden(attributes))\n                  {\n                     // MSDN: .NET 3.5+: IOException: The directory specified by path is read-only.\n\n                     if (ignoreReadOnly)\n                     {\n                        // Reset attributes to Normal.\n                        File.SetAttributesCore(transaction, true, pathLp, FileAttributes.Normal, PathFormat.LongFullPath);\n\n                        goto startRemoveDirectory;\n                     }\n\n\n                     // MSDN: .NET 3.5+: IOException: The directory is read-only.\n                     throw new DirectoryReadOnlyException(pathLp);\n                  }\n\n\n                  // MSDN: .NET 3.5+: UnauthorizedAccessException: The caller does not have the required permission.\n                  if (attributes == 0)\n                     NativeError.ThrowException(lastError, File.IsDirectory(attributes), pathLp);\n\n                  break;\n            }\n\n            // MSDN: .NET 3.5+: IOException:\n            // A file with the same name and location specified by path exists.\n            // The directory specified by path is read-only, or recursive is false and path is not an empty directory. \n            // The directory is the application's current working directory. \n            // The directory contains a read-only file.\n            // The directory is being used by another process.\n\n            NativeError.ThrowException(lastError, pathLp);","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.DeleteDirectoryNative.cs#L88-L124","documentation":"DeleteDirectoryNative throws DirectoryReadOnlyException with message '({145}) The file is read-only: [{pathLp}]' when the directory (or its items) carries the read-only attribute and deletion of the read-only item was not permitted (ignoreReadOnly false). Win32 reports ERROR_FILE_READ_ONLY / access issues for read-only items; AlphaFS maps it to DirectoryReadOnlyException after an attempt to clear attributes failed.","triggerScenarios":"Calling Directory.Delete / DeleteDirectoryCore on a directory marked read-only (FILE_ATTRIBUTE_READONLY) without ignoreReadOnly:true; deleting a folder containing read-only files where the recursive path attempted attribute clearing but the OS still refused; junction/special folders where Windows sets read-only on the directory itself.","commonSituations":"Folders copied from read-only media (CD/DVD) retain the read-only attribute; source-control or tool-set read-only flags; backup restores preserving read-only attributes; Windows system folders (some use read-only as a marker for customized/desktop.ini behavior).","solutions":["Retry the delete with the ignoreReadOnly option enabled so AlphaFS clears the read-only attribute first.","Clear attributes yourself: File.SetAttributes(path, FileAttributes.Normal) on offending items before deletion.","Remove the read-only attribute recursively (attrib -r /s /d or per-item) before Directory.Delete.","Take ownership/ACLs into account if attribute clearing fails due to permissions."],"exampleFix":"// before\nDirectory.Delete(roDir, true); // throws on read-only items\n// after\nforeach (var f in Directory.GetFiles(roDir, \"*\", SearchOption.AllDirectories))\n    File.SetAttributes(f, FileAttributes.Normal);\nFile.SetAttributes(roDir, FileAttributes.Directory);\nDirectory.Delete(roDir, true);","handlingStrategy":"try-catch","validationCode":"var attrs = File.GetAttributes(path);\nif ((attrs & FileAttributes.ReadOnly) != 0)\n    File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly);","typeGuard":null,"tryCatchPattern":"try { Directory.Delete(path, true); }\ncatch (DirectoryReadOnlyException) {\n    File.SetAttributes(path, FileAttributes.Normal);\n    Directory.Delete(path, true);\n}","preventionTips":["Clear ReadOnly attributes on files copied from read-only media","Run attrib -r /s /d on restored/backed-up trees before deletes","Use the ignoreReadOnly option of AlphaFS delete operations when allowed","Check attributes as part of pre-delete validation"],"tags":["windows","filesystem","read-only","delete"],"backgroundTag":"read-only-attribute-blocks-delete","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}