Skip to content

Instantly share code, notes, and snippets.

@drojf
Created March 29, 2020 06:46
Show Gist options
  • Save drojf/e004b040c032ea10d6053628aa5cfd58 to your computer and use it in GitHub Desktop.
Save drojf/e004b040c032ea10d6053628aa5cfd58 to your computer and use it in GitHub Desktop.
import os
def get_unity_version_from_file(filepath):
with open(filepath, 'rb') as file:
start_of_file = file.read(20)
version_string = file.read(7)
return version_string.decode('utf-8')
owd = os.getcwd()
for dir in os.listdir('.'):
print("Fixing dir", dir)
if 'higurashiep' not in dir.lower():
continue
# Go in the directory
os.chdir(dir)
for original_filename in os.listdir('.'):
_, ext = os.path.splitext(original_filename)
if ext != '.assets':
continue
if original_filename == 'sharedassets0.assets':
continue
new_filename = original_filename
# Read unity version from sharedassets file
unity_version_string = get_unity_version_from_file(new_filename)
# fix os in filename
new_filename = new_filename.replace('Win', 'Windows').replace("Lin", "Linux")
# add version to filename
split_filename = new_filename.split('-')
split_filename.insert(-1, unity_version_string)
new_filename = '-'.join(split_filename)
print(new_filename)
os.rename(original_filename, new_filename)
# Leave the directory
os.chdir(owd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment