import argparse
import secrets
import string
import random
parser = argparse.ArgumentParser()
parser.add_argument('input', help="inputs")
parser.add_argument("output", help="outputs")
parser.add_argument('search', help="search")
parser.add_argument('--replace', help='replace')
parser.add_argument('percent', help='percent')
args = parser.parse_args()
search_text = args.search
replace_text = args.replace
replace_text = ''.join(secrets.choice(string.ascii_letters + string.digits)
for i in range(10))
percent = int(args.percent)
data = open(args.input,'r').read()
nxt = 0
while True:
nxt = data.find( search_text, nxt )
if nxt < 0:
break
if random.randint(0,100) < percent:
data = data[:nxt] + replace_text + data[nxt+len(search_text):]
nxt += len(replace_text)
open(args.output,'w').write(data)
print(replace_text)
print("Text replaced")
I have a dataset containing different paths eg. 'C:\Windows\System32\autofmt.exe' etc. I have written a code to search a word from this path and add a random word in place of it. Now I want to add new directories to that path by taking input from user eg: C:dir1\dir2\dir3\System32\autofmt.exe is there any way I can do that
Aucun commentaire:
Enregistrer un commentaire