Skip to content

Instantly share code, notes, and snippets.

@Guaidaodl
Created July 5, 2016 15:35
Show Gist options
  • Save Guaidaodl/ef891985dd89e5a0500038b1dfe66279 to your computer and use it in GitHub Desktop.
Save Guaidaodl/ef891985dd89e5a0500038b1dfe66279 to your computer and use it in GitHub Desktop.
Python 批量重命名文件
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