codebox: File utilities¶
File utility tools
- codebox.file_tools.replace_in_files(files_map: Mapping[str, str], replace_map: Mapping[str, str])[source]¶
Replaces a series of matches in a collection of files
- Parameters
file_paths (dict) – A dictionary where the key is the file source and the value is a file target. If the target is set to an empty string, the original file will be replaced
replace_map (dict) – A dictionary where the keys are the regex to be matched and the value is the content to replace the match with
Example
>>> file_map = {'/tmp/source.txt': '/tmp/destination.txt'} >>> replace_map = {'.*foo.*': 'bar'} >>> replace_in_files(file_map, replace_map)