Created
August 19, 2022 05:26
-
-
Save jvkersch/95bd9a03eab05c18f9c0aeb1d8f7dcf0 to your computer and use it in GitHub Desktop.
This file contains 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
import os | |
import shutil | |
def parse_dirname(dirname): | |
_, raw_name, _ = dirname.split(" - ") | |
parts = raw_name.split() | |
parts = [parts[-1]] + parts[:-1] | |
return " ".join(parts) | |
def rename_one(dirname, new_dirname): | |
# print(f"mv {dirname!r} {new_dirname!r}") | |
shutil.move(dirname, new_dirname) | |
def rename_all(directory): | |
for entry in os.listdir(directory): | |
try: | |
new_dirname = parse_dirname(entry) | |
except Exception: | |
continue | |
rename_one(entry, new_dirname) | |
if __name__ == "__main__": | |
rename_all(".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment