peass-ng/PEASS-ng · error · FileNotFoundException
The system cannot find the file specified: [path]
Error message
The system cannot find the file specified: [path]
What it means
FileNotFoundException ('The system cannot find the file specified') thrown by ExistsDriveOrFolderOrFile when lastError is ERROR_FILE_NOT_FOUND and the target is NOT a folder. The final path component exists as neither a file nor directory at the probed location, and the caller asked to be told (throwIfFolderOrFileNotExists).
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.ExistsDrive.cs:94
throw new DeviceNotReadyException(drive, true);
throwIfFolderOrFileNotExists = throwIfFolderOrFileNotExists && lastError != Win32Errors.NO_ERROR;
if (throwIfFolderOrFileNotExists)
{
if (lastError != Win32Errors.NO_ERROR)
{
if (lastError == Win32Errors.ERROR_PATH_NOT_FOUND)
throw new DirectoryNotFoundException(regularPath);
if (lastError == Win32Errors.ERROR_FILE_NOT_FOUND)
{
if (isFolder)
throw new DirectoryNotFoundException(regularPath);
throw new FileNotFoundException(regularPath);
}
}
}
return driveExists;
}
}
}
View on GitHub (pinned to 53fb989abc)
Solutions
- Correct the file path (verify spelling, extension, and expected install location).
- Regenerate/install the missing file, or copy it from a known-good source.
- Catch FileNotFoundException and treat as absent if the check is advisory.
- Search alternates (Directory.EnumerateFiles with a search pattern) when the exact name may vary.
Example fix
// before
bool hasLicense = Directory.ExistsDrive(licensePath, true, true);
// after
bool hasLicense = File.Exists(licensePath);
if (!hasLicense) Log.Warn("license file missing: " + licensePath); Defensive patterns
Strategy: validation
Validate before calling
if (!File.Exists(filePath)) { Log.Warn("missing file: " + filePath); return false; } Try / catch
try { ok = Directory.ExistsDrive(filePath, true, true); } catch (FileNotFoundException ex) { Log.Warn($"file not found: {ex.FileName}"); ok = false; } Prevention
- Use File.Exists / DirectoryInfo.Exists instead of throwing variants when absence is expected.
- Verify file paths against the current product version's install layout.
- Search with wildcards when filenames may vary across versions.
When it happens
Trigger: Directory.ExistsDrive(filePath, throwIfFolderOrFileNotExists:true) where the file itself is absent — e.g. probing a specific file path that was deleted, never installed, or misspelled while its parent directory exists.
Common situations: Looking for a marker file/license file/config file that a different product version stores elsewhere; files removed by cleanup tools or antivirus quarantine; probing files on a freshly imaged machine.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/91a80de9dbebda5a.
Report an issue: GitHub.