Replace the Content in Files
Your task is to develop a script that can replace a specific string in all .txt
files in a given directory.
Imagine that you are working as a data analyst for a large company and your team has just asked you to modify a key term that appears in many different report files. The files are all stored in one directory, and all have a .txt
extension. The task would be cumbersome to do manually, but thankfully, you know how to automate the process with a script.
The first line of the input contains the string s
that you need to find in the files. The second line of the input contains the string r
that you will replace s
with. The third line of the input contains the directory where the files are located.
The program should go through all .txt
files in directory d
, find all occurrences of string s
and replace them with string r
. The program doesn't need to output anything.
Input | Output |
---|---|
2022 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB