{"record":{"id":"f90bc0e7b92d164e","repo":"sharkdp/fd","slug":"the-search-pattern-pattern-contains-a-path-sep","errorCode":null,"errorMessage":"The search pattern '{pattern}' contains a path-separation character and will not lead to any search results.\n\nIf you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n  fd . '{pattern}'\n\nInstead, if you want your pattern to match the full file path, use:\n\n  fd --full-path '{pattern}'","messagePattern":"The search pattern '(.+?)' contains a path-separation character and will not lead to any search results\\.\n\nIf you want to search for all files inside the '(.+?)' directory, use a match-all pattern:\n\n  fd \\. '(.+?)'\n\nInstead, if you want your pattern to match the full file path, use:\n\n  fd --full-path '(.+?)'","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":204,"sourceCode":"    // Start with the cheap check: '/' is always a path separator, including on\n    // Windows, and has no regex meaning, so flagging it is safe and catches the\n    // Linux/macOS mistake of pasting a full path as the pattern.\n    #[cfg_attr(not(windows), allow(unused_mut))]\n    let mut should_warn = pattern.contains('/');\n\n    // On Windows we additionally accept the native `\\` separator, but only when\n    // the pattern actually resolves to an existing directory - `\\` is also the\n    // regex escape char there, so valid patterns like `\\Ac` or `\\d+` must still\n    // run. The is_dir syscall is only needed when `should_warn` is still false,\n    // so short-circuit via `||` to avoid the stat call on the happy path.\n    #[cfg(windows)]\n    {\n        should_warn = should_warn\n            || (pattern.contains(std::path::MAIN_SEPARATOR) && Path::new(pattern).is_dir());\n    }\n\n    if should_warn {\n        Err(anyhow!(\n            \"The search pattern '{pattern}' contains a path-separation character \\\n             and will not lead to any search results.\\n\\n\\\n             If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\\n\\n  \\\n             fd . '{pattern}'\\n\\n\\\n             Instead, if you want your pattern to match the full file path, use:\\n\\n  \\\n             fd --full-path '{pattern}'\",\n            pattern = pattern,\n        ))\n    } else {\n        Ok(())\n    }\n}\n\nfn build_pattern_regex(pattern: &str, opts: &Opts) -> Result<String> {\n    Ok(if opts.glob && !pattern.is_empty() {\n        let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;\n        glob.regex().to_owned()\n    } else if opts.exact {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/sharkdp/fd/blob/ee20f426ddf338ac7ead5c5f00ea49258005caaf/src/main.rs#L186-L222","documentation":"Without --full-path, fd matches the pattern against the file name only, so any '/' in the pattern can never match and would silently yield zero results. ensure_single_search_pattern_is_not_a_path (main.rs:185) detects this and returns a helpful error instead. On Windows, '\\' is also flagged but only when the pattern resolves to an existing directory, since '\\' is also the regex escape char. This applies to the primary pattern and every --and pattern.","triggerScenarios":"Running `fd /home/user/foo`, `fd src/main.rs`, or `fd --and lib/utils`. The cheap '/' check always flags it; on Windows the '\\' branch additionally requires Path::new(pattern).is_dir().","commonSituations":"Pasting a full path instead of a file name; muscle memory from `find path`; scripts that interpolate full paths into the pattern position.","solutions":["Search by file name only: `fd foo` instead of `fd /home/user/foo`.","To list everything under a directory, use a match-all pattern: `fd . /home/user/foo`.","To match against the full path, add --full-path: `fd --full-path /home/user/foo`."],"exampleFix":"# before\nfd /home/user/src\n\n# after (list contents of that dir)\nfd . /home/user/src\n# or match full paths\nfd --full-path home/user/src","handlingStrategy":"validation","validationCode":"if printf '%s' \"$PATTERN\" | grep -q '/'; then\n  # pattern is a path; pass it as a search path instead\n  fd . \"$PATTERN\"\nelse\n  fd \"$PATTERN\"\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Search by file name, not full path, unless using --full-path.","Validate user-supplied patterns for '/' before passing to fd.","Use `fd . <dir>` to list a directory's contents."],"tags":["pattern","path-separator","cli","search"],"backgroundTag":null,"analyzedSha":"ee20f426ddf338ac7ead5c5f00ea49258005caaf","analyzedAt":"2026-08-09T08:21:40.573Z","contentChangedAt":"2026-08-09T08:21:40.573Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}