sharkdp/fd · error · anyhow::Error

The '--base-directory' path '{}' is not a directory.

Error message

The '--base-directory' path '{}' is not a directory.

What it means

Thrown by set_working_dir in src/main.rs:134 when --base-directory resolves via filesystem::is_existing_directory to something that is not a directory (a regular file, a broken path, or a path that doesn't exist at all). fd chdirs into that directory before walking, so it must be a real directory.

Source

Thrown at src/main.rs:134

fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {
    // The program name is the first argument.
    let first_arg = env::args().next();
    let program_name = first_arg
        .as_ref()
        .map(Path::new)
        .and_then(|path| path.file_stem())
        .and_then(|file| file.to_str())
        .unwrap_or("fd");
    let mut cmd = Opts::command();
    cmd.build();
    clap_complete::generate(shell, &mut cmd, program_name, &mut std::io::stdout());
    Ok(ExitCode::Success)
}

fn set_working_dir(opts: &Opts) -> Result<()> {
    if let Some(ref base_directory) = opts.base_directory {
        if !filesystem::is_existing_directory(base_directory) {
            return Err(anyhow!(
                "The '--base-directory' path '{}' is not a directory.",
                base_directory.to_string_lossy()
            ));
        }
        env::set_current_dir(base_directory).with_context(|| {
            format!(
                "Could not set '{}' as the current working directory",
                base_directory.to_string_lossy()
            )
        })?;
    }
    Ok(())
}

/// Detect if the user accidentally supplied a path instead of a search pattern.
///
/// Without `--full-path`, fd matches patterns against file names, so any pattern
/// containing a path separator can never match. This applies to the primary

View on GitHub (pinned to 41532d114e)

Solutions

  1. Confirm the path exists and is a directory: 'test -d <path> && fd --base-directory <path> ...'.
  2. Use an unquoted tilde or $HOME so the shell expands it: 'fd --base-directory "$HOME"/src'.
  3. Drop --base-directory and pass the directory as the search path positional argument instead.

Example fix

// before
fd --base-directory /etc/passwd foo

// after
fd --base-directory /etc foo
Defensive patterns

Strategy: validation

Validate before calling

if [ ! -d "$BASE_DIR" ]; then
  echo "--base-directory is not a directory: $BASE_DIR" >&2; exit 1
fi
fd --base-directory "$BASE_DIR" "$@"

Type guard

fn is_real_dir(p: &std::path::Path) -> bool {
    p.is_dir() // true only for existing directories
}

Prevention

When it happens

Trigger: Passing 'fd --base-directory /etc/passwd' (a file), 'fd --base-directory /no/such/dir', or a path that exists only as a symlink to a missing target.

Common situations: Config typo; using a tilde that wasn't expanded (e.g. quoted '~'); pointing at a path on an unmounted volume; copy-pasting a file path where a directory was expected.

Related errors


AI-assisted analysis of sharkdp/fd@41532d114e (2026-08-06). Data as JSON: /data/errors/d837eb09f2bd749c.json. Report an issue: GitHub.