Skip to content

Instantly share code, notes, and snippets.

@spdskatr
Created August 7, 2018 02:09
Show Gist options
  • Save spdskatr/f674a652b50088dcad37901e45ec596c to your computer and use it in GitHub Desktop.
Save spdskatr/f674a652b50088dcad37901e45ec596c to your computer and use it in GitHub Desktop.
Renames <targetVersion> tag in any mod's about.xml from 1.0 to current version. Place this file in the same folder as rw's executable to run.
"""
@author: Spdskatr
Renames <targetVersion> tag in any mod's about.xml from 1.0 to current version.
Place this file in the same folder as rw's executable to run.
To change Steam Workshop mods as well, change modsPath to "../../workshop/content/294100"
"""
from __future__ import print_function
import re
import os
pattern = r"<targetVersion>1\.0[^<>]*<\/targetVersion>"
currentVer = "0.19.1987"
modsPath = "Mods"
for root, dirs, files in os.walk(modsPath):
for fl in files:
if fl.endswith("About.xml"):
try:
path = os.path.join(root, fl)
with open(path) as f:
text = f.read()
with open(path, "w") as f:
f.write(re.sub(pattern, f"<targetVersion>{currentVer}</targetVersion>", text))
except Exception as e:
print("Error processing file %s: " % path)
print(e)
print(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment