Suppose I have a bunch of files labeled as such:
- SUS200_One.txt
- SUS300_Two.txt
- SUS400_Three.txt
I want to remove the SUSxxx portion of each txt file in a certain directory. I have the regular expression pattern correct and I'm able to find the expression on each file when I perform a loop on the directory. However, I just don't know how I go about removing it. For example, I want each file to have the SUSXXX removed and have each file left with _One, _Two, _Three, respectively. Below is what I have so far. For some reason, I cannot figure this out, as simple as this may be. Any help would be appreciated.
rootdir = ('C:\\Test')
pattern = re.compile(r'\w{3}\d{3}')
def removeChar():
for filename in os.listdir(rootdir):
findpattern = pattern.findall(filename)
removeChar()