democritus-project / d8s-file-system

Democritus functions for working with files and directories.
GNU Lesser General Public License v3.0
1 stars 0 forks source link

Write function to replace given text in all files in a given directory #5

Open fhightower opened 3 years ago

fhightower commented 3 years ago

What?

(See issue title)

Why?

This is a common use-case that would be helpful to have.

How?

I recommend writing a function with the following signature:

def directory_replace_text_in_files(directory_path: str, old: str, new: str, *, recursive: bool = False) -> Iterator[str]:
    ...

For the directory path, it would be nice to accept a Pathlib.Path or str. The function should yield file_paths that were updated.