Kareadita/Kavita · error · DirectoryNotFoundException

Source directory does not exist or could not be found:

Error message

Source directory does not exist or could not be found: 

What it means

A standard .NET DirectoryNotFoundException thrown by CopyDirectoryToDirectory when the source directory path does not exist on disk. The code creates a DirectoryInfo wrapper via the abstracted FileSystem and checks dir.Exists before proceeding. Unlike KavitaException, this is a raw BCL exception that will propagate as a 500 if uncaught.

Source

Thrown at Kavita.Services/DirectoryService.cs:249

    /// <summary>
    /// Copies all files and subdirectories within a directory to a target location
    /// </summary>
    /// <param name="sourceDirName">Directory to copy from. Does not copy the parent folder</param>
    /// <param name="destDirName">Destination to copy to. Will be created if doesn't exist</param>
    /// <param name="searchPattern">Defaults to all files</param>
    /// <returns>If was successful</returns>
    /// <exception cref="DirectoryNotFoundException">Thrown when source directory does not exist</exception>
    public bool CopyDirectoryToDirectory(string? sourceDirName, string destDirName, string searchPattern = "")
    {
        if (string.IsNullOrEmpty(sourceDirName)) return false;

        // Get the subdirectories for the specified directory.
        var dir = FileSystem.DirectoryInfo.New(sourceDirName);

        if (!dir.Exists)
        {
            throw new DirectoryNotFoundException(
                "Source directory does not exist or could not be found: "
                + sourceDirName);
        }

        var dirs = dir.GetDirectories();

        // If the destination directory doesn't exist, create it.
        ExistOrCreate(destDirName);

        // Get the files in the directory and copy them to the new location.
        var files = GetFilesWithExtension(dir.FullName, searchPattern).Select(n => FileSystem.FileInfo.New(n));
        foreach (var file in files)
        {
            var tempPath = FileSystem.Path.Combine(destDirName, file.Name);
            file.CopyTo(tempPath, false);
        }

        // If copying subdirectories, copy them and their contents to new location.

View on GitHub (pinned to 9c3e540000)

Solutions

  1. Verify the source directory path exists at the OS level: 'ls /path/to/source' or equivalent
  2. If the library root moved, update the library folder configuration in Kavita Settings
  3. Check that the volume or mount point is active in container deployments
  4. Verify the Kavita process user has read + traverse permissions on the source directory

Example fix

// Guard before copying:
// if (!directoryService.FileSystem.Directory.Exists(sourceDirName)) {
//     logger.LogWarning("Source directory not found: {Path}", sourceDirName);
//     return false;
// }
Defensive patterns

Strategy: validation

Validate before calling

// Check directory existence before copying:
// if (!directoryService.FileSystem.Directory.Exists(sourceDirName)) {
//     logger.LogWarning("Source directory not found: {Path}", sourceDirName);
//     return false;
// }

Try / catch

// try {
//     directoryService.CopyDirectoryToDirectory(sourceDir, destDir, searchPattern);
// } catch (DirectoryNotFoundException ex) {
//     logger.LogWarning(ex, "Source directory missing: {Path}", sourceDir);
//     return false; // or re-scan library
// }

Prevention

When it happens

Trigger: Source directory path is misspelled, has been moved or deleted, lives on an unmounted network share, or the process lacks permissions to enumerate the directory (Exists can return false for inaccessible paths).

Common situations: Library root moved after initial scan; NAS or USB drive disconnected; path casing issues on case-sensitive filesystems; containerized deployment with a misconfigured volume mount; permissions changed by another process.

Related errors


AI-assisted analysis of Kareadita/Kavita@9c3e540000 (2026-08-13). Data as JSON: /api/errors/0b8fdd031450c099. Report an issue: GitHub.