Created
March 29, 2017 11:37
-
-
Save jinyu121/ca84c743e21f5e7507ef6d4747b0eb76 to your computer and use it in GitHub Desktop.
将杂乱无章的文件重命名
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
import re | |
import os.path | |
rootdir = "/home/haoyu/pictures" | |
fn_ext = ".png" | |
pattern_ith = re.compile(r"\((\d+)\)") | |
for parent, dirnames, filenames in os.walk(rootdir): | |
for filename in filenames: | |
ith = pattern_ith.findall(filename) | |
fn_ori = os.path.join(rootdir, filename) | |
fn_dst = os.path.join(rootdir, ith[0] + fn_ext) | |
print(fn_ori,"\n\t==>\t",fn_dst) | |
os.rename(fn_ori, fn_dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment