Last active
September 26, 2015 05:44
-
-
Save yy0c/11fb62ab05c83025ab16 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
#!/usr/bin/env python2 | |
#-*- coding: utf-8 -*- | |
import os | |
import re | |
import shutil | |
SOURCEDIR = "/home/hiro/source/" | |
DESTDIR = "/home/hiro/outputdir/" | |
def main(): | |
sub_dirs = [] | |
for root, dirs, files in os.walk(SOURCEDIR, False): | |
for subdir in dirs: | |
sub_dirs.append(subdir) | |
for subdir in sub_dirs: | |
num = re.findall(r'[\d|.]+', subdir) | |
if not num: | |
continue | |
else: | |
num = num[0] | |
for i, subfile in enumerate(sorted(os.listdir(subdir))): | |
sourcepic = "%s%s/%s" % (SOURCEDIR, subdir, subfile) | |
targetpic = "%s%s%02d.jpg" % (DESTDIR, num, i) | |
shutil.copy(sourcepic, targetpic) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment