Created
September 27, 2020 01:38
-
-
Save AllanChain/e923317a381b7de12ba06a0b7ff0f8f5 to your computer and use it in GitHub Desktop.
Removes parentheses in filename. Very useful for files downloaded from course.pku.edu.cn
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
from sys import argv | |
import os | |
import re | |
pattern = re.compile(r'^(.*?)(\(\d+\))+\.(.*?)$') | |
if __name__ == "__main__": | |
for file_to_rename in argv[1:]: | |
if os.path.isfile(file_to_rename): | |
match_result = re.match(pattern, file_to_rename) | |
if match_result is not None: | |
g = match_result.groups() | |
os.rename(file_to_rename, f'{g[0]}.{g[2]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment