2dust/v2rayN · error · DirectoryNotFoundException
Source directory not found: {dir.FullName}
Error message
Source directory not found: {dir.FullName} What it means
Thrown by FileUtils.CopyDirectory when the DirectoryInfo built from sourceDir does not exist on disk. It is a hard precondition check before any file/directory enumeration and copy.
Source
Thrown at v2rayN/ServiceLib/Common/FileUtils.cs:166
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, CompressionLevel.SmallestSize, true);
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
return false;
}
return true;
}
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, bool overwrite, string? ignoredName = null)
{
// Get information about the source directory
var dir = new DirectoryInfo(sourceDir);
// Check if the source directory exists
if (!dir.Exists)
{
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
}
// Cache directories before we start copying
var dirs = dir.GetDirectories();
// Create the destination directory
_ = Directory.CreateDirectory(destinationDir);
// Get the files in the source directory and copy to the destination directory
foreach (var file in dir.GetFiles())
{
if (ignoredName.IsNotEmpty() && file.Name.Contains(ignoredName))
{
continue;
}
if (file.Extension == file.Name)
{
continue;View on GitHub (pinned to e01717d832)
Solutions
- Verify sourceDir exists and is a directory before calling CopyDirectory (Directory.Exists).
- Log/expand the absolute path (Path.GetFullPath) so typos and bad env-var expansion are visible.
- If the source may be optional, branch on Directory.Exists instead of letting it throw.
- For network/removable sources, confirm the mount/share is available first.
Example fix
// before
FileUtils.CopyDirectory(maybeMissingPath, dest, true, true);
// after
if (!Directory.Exists(maybeMissingPath))
{
throw new DirectoryNotFoundException($"Backup source not found: {Path.GetFullPath(maybeMissingPath)}");
}
FileUtils.CopyDirectory(maybeMissingPath, dest, true, true); Defensive patterns
Strategy: validation
Validate before calling
var full = Path.GetFullPath(sourceDir);
if (!Directory.Exists(full))
throw new DirectoryNotFoundException($"Source directory not found: {full}");
FileUtils.CopyDirectory(full, destinationDir, recursive, overwrite, ignoredName); Type guard
static bool IsExistingDirectory(string path) => !string.IsNullOrWhiteSpace(path) && Directory.Exists(path);
Try / catch
try
{
FileUtils.CopyDirectory(sourceDir, destinationDir, true, true);
}
catch (DirectoryNotFoundException ex)
{
// source path missing/typo; check config and mount state
_log?.Error(ex.Message);
} Prevention
- Always Directory.Exists-check before copying.
- Expand to an absolute path with Path.GetFullPath to expose typos and bad env vars.
- For network/removable sources, verify the mount/share first.
When it happens
Trigger: CopyDirectory(sourceDir, ...) is called with a path that does not resolve to an existing directory; dir.Exists is false.
Common situations: User-configured source path is wrong or relative to an unexpected working directory; the directory was deleted/renamed between config and call; a removable/network drive is unmounted; path contains typos or environment variables that expanded to nothing.
Related errors
- SOCKS5 address type {AddressType} not supported.
- Failed to build UDP request packet.
- webdav parameter error or null
AI-assisted analysis of 2dust/v2rayN@e01717d832 (2026-08-13).
Data as JSON: /api/errors/d0ea08296a9bc6cd.
Report an issue: GitHub.