'Python search a specific text file in multiple subdirectories for a specific string & then replace another string within same file with found string
Python search a specific text file in multiple subdirectories for a specific string & then replace another string within same file with found string.
To explain this case: I have a bunch of *.xml files in multiple directories and each of these files contains two strings at different locations.
<spirit:name>I_want_to_take_this_string</spirit:name>
<spirit:modelName>And_paste_it_here</spirit:modelName>
What I am trying to do is to take the string value I_want_to_take_this_string and replace And_paste_it_here within the same file, then move on to the next file and then move on to the next until it can't find any more files to make the swap.
The output should look like this
<spirit:name>I_want_to_take_this_string</spirit:name>
<spirit:modelName>I_want_to_take_this_string</spirit:modelName>
I believe it's probably the easiest thing to do here but this is the first python code I want to write as a beginner.
Thanks in advance for helping with this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
