{"record":{"id":"d0ea08296a9bc6cd","repo":"2dust/v2rayN","slug":"source-directory-not-found-dir-fullname","errorCode":null,"errorMessage":"Source directory not found: {dir.FullName}","messagePattern":"Source directory not found: (.+?)","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib/Common/FileUtils.cs","lineNumber":166,"sourceCode":"            ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, CompressionLevel.SmallestSize, true);\n        }\n        catch (Exception ex)\n        {\n            Logging.SaveLog(_tag, ex);\n            return false;\n        }\n        return true;\n    }\n\n    public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, bool overwrite, string? ignoredName = null)\n    {\n        // Get information about the source directory\n        var dir = new DirectoryInfo(sourceDir);\n\n        // Check if the source directory exists\n        if (!dir.Exists)\n        {\n            throw new DirectoryNotFoundException($\"Source directory not found: {dir.FullName}\");\n        }\n\n        // Cache directories before we start copying\n        var dirs = dir.GetDirectories();\n\n        // Create the destination directory\n        _ = Directory.CreateDirectory(destinationDir);\n\n        // Get the files in the source directory and copy to the destination directory\n        foreach (var file in dir.GetFiles())\n        {\n            if (ignoredName.IsNotEmpty() && file.Name.Contains(ignoredName))\n            {\n                continue;\n            }\n            if (file.Extension == file.Name)\n            {\n                continue;","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib/Common/FileUtils.cs#L148-L184","documentation":"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.","triggerScenarios":"CopyDirectory(sourceDir, ...) is called with a path that does not resolve to an existing directory; dir.Exists is false.","commonSituations":"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.","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."],"exampleFix":"// before\nFileUtils.CopyDirectory(maybeMissingPath, dest, true, true);\n\n// after\nif (!Directory.Exists(maybeMissingPath))\n{\n    throw new DirectoryNotFoundException($\"Backup source not found: {Path.GetFullPath(maybeMissingPath)}\");\n}\nFileUtils.CopyDirectory(maybeMissingPath, dest, true, true);","handlingStrategy":"validation","validationCode":"var full = Path.GetFullPath(sourceDir);\nif (!Directory.Exists(full))\n    throw new DirectoryNotFoundException($\"Source directory not found: {full}\");\nFileUtils.CopyDirectory(full, destinationDir, recursive, overwrite, ignoredName);","typeGuard":"static bool IsExistingDirectory(string path) => !string.IsNullOrWhiteSpace(path) && Directory.Exists(path);","tryCatchPattern":"try\n{\n    FileUtils.CopyDirectory(sourceDir, destinationDir, true, true);\n}\ncatch (DirectoryNotFoundException ex)\n{\n    // source path missing/typo; check config and mount state\n    _log?.Error(ex.Message);\n}","preventionTips":["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."],"tags":["filesystem","io","copy","validation"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}