MCPcopy Create free account
hub / github.com/dot-agent/nextpy / find_replace

Function find_replace

nextpy/utils/path_ops.py:182–197  ·  view source on GitHub ↗

Recursively find and replace text in files in a directory. Args: directory: The directory to search. find: The text to find. replace: The text to replace.

(directory: str, find: str, replace: str)

Source from the content-addressed store, hash-verified

180
181
182def find_replace(directory: str, find: str, replace: str):
183 """Recursively find and replace text in files in a directory.
184
185 Args:
186 directory: The directory to search.
187 find: The text to find.
188 replace: The text to replace.
189 """
190 for root, _dirs, files in os.walk(directory):
191 for file in files:
192 filepath = os.path.join(root, file)
193 with open(filepath, "r", encoding="utf-8") as f:
194 text = f.read()
195 text = re.sub(find, replace, text)
196 with open(filepath, "w") as f:
197 f.write(text)

Callers

nothing calls this directly

Calls 2

joinMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected