{"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/41532d114e2ba565fb5367d606c111b29b96450c/src/main.rs#L186-L222","documentation":"Thrown by ensure_single_search_pattern_is_not_a_path in src/main.rs:204. Without --full-path, fd matches the pattern against the file name only, so any '/' in the pattern (or, on Windows, a '\\' naming an existing directory) can never match. Rather than return zero results silently, fd aborts with guidance. This applies to the primary pattern and every --and pattern.","triggerScenarios":"Running 'fd /home/user', 'fd src/foo.rs', or on Windows 'fd C:\\Users' (when that path is an existing dir), all without --full-path.","commonSituations":"Pasting a full path expecting substring matching; muscle memory from 'find /path'; treating the first positional as a path rather than a regex.","solutions":["To list files under a directory, use a match-all pattern: 'fd . /home/user'.","To match the full path as a regex, enable --full-path: 'fd --full-path /home/user'.","Quote the literal path and add --fixed-strings --full-path if you want a plain substring over the whole path."],"exampleFix":"// before\nfd src/foo.rs\n\n// after\nfd --full-path 'src/foo.rs'","handlingStrategy":"validation","validationCode":"# if the pattern contains a path separator, switch modes explicitly\nif printf '%s' \"$PAT\" | grep -Eq '[/\\\\]'; then\n  fd --full-path --fixed-strings \"$PAT\" \"$@\"\nelse\n  fd \"$PAT\" \"$@\"\nfi","typeGuard":"fn looks_like_path(s: &str) -> bool {\n    s.contains('/')\n}","tryCatchPattern":null,"preventionTips":["If you want to list files under a directory, use 'fd . <dir>'.","If you want full-path matching, always pass --full-path.","Treat the first positional as a regex against the file name, not a path."],"tags":["search-pattern","path-separator","user-guidance","cli-flag"],"analyzedSha":"41532d114e2ba565fb5367d606c111b29b96450c","analyzedAt":"2026-08-06T01:39:28.509Z","schemaVersion":2}