from pathlib import Path old_name = "LD-FDPI_1.5.10_44a7360_x64-setup.exe" new_name = "LD-FDPI_1.5.10_568239d_x64-setup.exe" old_query = "?v=44a7360" new_query = "?v=568239d" for path in [ Path('/opt/tylorindar-safelink/static/index.html'), Path('/opt/tylorindar-safelink/static/downloads/ld-fdpi.html'), ]: text = path.read_text(encoding='utf-8') text = text.replace(old_name, new_name).replace(old_query, new_query) path.write_text(text, encoding='utf-8') print('updated', path)