Created
July 5, 2016 15:35
-
-
Save Guaidaodl/ef891985dd89e5a0500038b1dfe66279 to your computer and use it in GitHub Desktop.
Python 批量重命名文件
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 re | |
file_name_pattern = re.compile("^(.*)\\s\\(\\d\\)(\\..*)$") | |
for file_name in os.listdir("."): | |
matcher = file_name_pattern.match(file_name) | |
if matcher is not None: | |
new_file_name = matcher.group(1) + matcher.group(2) | |
os.rename(file_name, new_file_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment