pub fn replace_str_in_files<P: AsRef<Path>>(
path: P,
old_string: &str,
new_string: &str,
)Expand description
Replaces all occurrences of a string in all files within a directory (including subdirectories).
§Arguments
path- Path to the directory or file where the replacements will be performed (can be a&str,String,Path, orstd::path::PathBuf).old_string- The substring to find and replace in all files.new_string- The replacement string.
§Note
This function will not panic if a single read/write fails (since this function may pull in
private, inaccessible files). However, a warning will be printed to stderr.
§Examples
ⓘ
use file_io::replace_str_in_files;
let dir = Path::new("/path/to/folder");
// Replace "foo" with "bar" in all files within the "/path/to/folder/" directory (including
// subdirectories).
replace_str_in_files(dir, "foo", "bar");