import os
import glob
from pprint import pprint
source = r""
source = input(r"Enter directory: ")
while True:
try:
pathiter = (os.path.join(root, filename)
for root, _, filenames in os.walk(source)
for filename in filenames)
pprint(r"In " + source + ":")
oldtxt = input("Current Text: ")
newtxt = input("Replace With: ")
for path in pathiter:
newname = path.replace(oldtxt, newtxt)
if newname != path:
os.rename(path, newname)
pprint(r"Would you like to modify another string in the current directory?")
pprint(r"Y (yes) / N (no) / C (change directory): ")
choice = input("> ")
if choice.lower() == "y":
continue
elif choice.lower() == "n":
break
elif choice.lower() == "c":
source = input("Enter directory: ")
continue
else:
pprint("Invalid response.")
except Exception as e:
print (e + " : " + newname)