remove files rather than overwrite

This commit is contained in:
OddlyTimbot 2024-09-21 21:31:09 -04:00
parent 0b05c0ac38
commit a53ecbf8f0

View File

@ -15,6 +15,9 @@ def replace_word_in_files(target_word, replacement_word, folder_path=".", dest_p
# Write the new content back to the file # Write the new content back to the file
file_path = os.path.join(dest_path, filename) file_path = os.path.join(dest_path, filename)
if os.path.exists(file_path):
os.remove(dst_file)
with open(file_path, 'w') as file: with open(file_path, 'w') as file:
file.write(new_content) file.write(new_content)
@ -29,7 +32,9 @@ def copy_png_files_up():
if filename.endswith(".png"): # Check if the file is a .png file if filename.endswith(".png"): # Check if the file is a .png file
source_path = os.path.join(current_dir, filename) source_path = os.path.join(current_dir, filename)
destination_path = os.path.join(parent_dir, filename) destination_path = os.path.join(parent_dir, filename)
if os.path.exists(destination_path):
os.remove(destination_path)
# Copy the .png file to the parent directory # Copy the .png file to the parent directory
shutil.copy(source_path, destination_path) shutil.copy(source_path, destination_path)
print(f"Copied: {filename} to {parent_dir}") print(f"Copied: {filename} to {parent_dir}")