Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- try:
- import os,shutil,sys
- except ImportError:
- print "[!] One or more library is missing...\n\n"
- exit(-1)
- current_dir = '.'
- if len(sys.argv) != 3:
- print 'Usage:\n\n%s <old_value> <new_value>\n\n' % (sys.argv[0])
- exit(-1)
- for subdirs, dirs, files in os.walk(current_dir):
- for item in files:
- old_value = sys.argv[1].lower()
- new_value = sys.argv[2]
- #Getting a backup of the file
- shutil.copyfile(os.path.join(subdirs,item),os.path.join(subdirs,item)+'.backup')
- #Checking filename if it contains old value
- item_name = os.path.join(subdirs,item).lower()
- fp = open(item,'r')
- file_contents = fp.read()
- new_file_contents = file_contents.replace(old_value, new_value)
- if item_name.find(old_value) == -1:
- fp.write(new_file_contents)
- else:
- new_fp = open(item_name.replace(old_value, new_value),'w')
- new_fp.write(new_file_contents)
- new_fp.close()
- fp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement