31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import os
|
|
import getpass
|
|
|
|
def replace_word_in_files(target_word, replacement_word, folder_path=".", dest_path=".."):
|
|
# Loop through all files in the specified folder
|
|
for filename in os.listdir(folder_path):
|
|
if filename.endswith(".desktop"): # Only process text files
|
|
file_path = os.path.join(folder_path, filename)
|
|
with open(file_path, 'r') as file:
|
|
file_content = file.read()
|
|
|
|
# Replace the target word with the replacement word
|
|
new_content = file_content.replace(target_word, replacement_word)
|
|
|
|
# Write the new content back to the file
|
|
file_path = os.path.join(dest_path, filename)
|
|
with open(file_path, 'w') as file:
|
|
file.write(new_content)
|
|
|
|
print(f"Replaced '{target_word}' with '{replacement_word}' in {filename}")
|
|
|
|
if __name__ == "__main__":
|
|
# Get the current Ubuntu username
|
|
username = getpass.getuser()
|
|
|
|
# Replace 'TARGET_WORD' in all text files with the username
|
|
target_word = "userhere"
|
|
|
|
replace_word_in_files(target_word, username)
|
|
|