Created
August 11, 2023 14:24
-
-
Save Yanis002/94c61550c4e94e2aee733d9a4b271752 to your computer and use it in GitHub Desktop.
rename gz savestates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os import walk, rename | |
| # set the filenames without the index here | |
| # the index will be added automatically later | |
| # what I'm doing is: 1. make the state, 2. export it and 3. write the corresponding name in notepad | |
| # then simply copy paste there and add the ``"`` for the syntax | |
| names = [ | |
| "Link's House", | |
| "KF From Shop", | |
| "Aqua Escape", | |
| "Collapse Skip", | |
| "Double Kiss", | |
| "Ganon", | |
| ] | |
| # path the savestates folder (relative to this file's location) | |
| statePath = "./savestates/" | |
| # change this to select the files to keep (extension filter) | |
| fileFilter = ".gzs" | |
| # change this to change the characters between the index and the name | |
| # i.e: ``inBetween = " - "`` will output "10 - Ganon.gzs" | |
| inBetween = " - " | |
| # get the current files | |
| files = [] | |
| for (_, _, filenames) in walk(statePath): | |
| files.extend(filenames) | |
| # remove the files we don't want | |
| for file in files: | |
| if fileFilter not in file: | |
| files.remove(file) | |
| # make sure the length of the found files is the same as | |
| # the length of the names provided by the user | |
| assert len(files) == len(names) | |
| # rename the files | |
| for i, file in enumerate(files, 1): | |
| prefix = f"{i:02}" if len(files) < 100 else f"{i:03}" | |
| # replace rename by print if you want a preview | |
| rename(statePath + file, statePath + prefix + inBetween + f"{names[i - 1]}.gzs") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(make sure to not have any invalid filename characters in the name list and it should be fine)