@@ -0,0 +1,2205 @@
+# -*- coding: UTF-8 -*-%0A# Created by mcxiaoke on 2015/7/6 22:20.%0A__author__ = 'mcxiaoke'%0A%0Aimport sys, os%0Afrom os import path%0Afrom datetime import datetime%0A%0Aprint 'curren dir is', os.getcwd()%0Aprint 'command line args is', sys.argv%0A%0Aif len(sys.argv) %3C 2:%0A    sys.exit(1)%0A%0A# %E6%89%B9%E9%87%8F%E9%87%8D%E5%91%BD%E5%90%8D%E7%85%A7%E7%89%87%E6%96%87%E4%BB%B6%0A# %E6%A0%B9%E6%8D%AE%E6%96%87%E4%BB%B6%E4%BF%AE%E6%94%B9%E6%97%A5%E6%9C%9F%E9%87%8D%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6%EF%BC%8C%E7%84%B6%E5%90%8E%E7%A7%BB%E5%8A%A8%E5%88%B0%E7%9B%AE%E6%A0%87%E6%96%87%E4%BB%B6%E5%A4%B9%0A# input:$%7Binput%7D/some_dir/xxxx.jpg%0A# output: $%7Boutput%7D/year/month/IMG_YYYYmmdd_HHMMSS.jpg%0ADIR_NAME_FORMAT = %22%25Y/%25m%22%0AFILE_NAME_FORMAT = %22IMG_%25Y%25m%25d_%25H%25M%25S%22%0Astart_dir = path.abspath(sys.argv%5B1%5D)%0Aoutput_dir = path.join(path.dirname(start_dir), 'output')%0Aif not path.exists(output_dir):%0A    os.mkdir(output_dir)%0Aprint 'start dir is %25s' %25 start_dir%0Aprint 'output dir is %25s' %25 output_dir%0A%0Atasks = %5B%5D%0A%0A%0Adef handler(arg, dirname, names):%0A    dir_path = path.join(dirname, dirname)%0A    print (%22current dir is %25s%22 %25 dir_path)%0A    for file in names:%0A        file_path = path.abspath(path.join(dirname, file))%0A        print %22processing file: %25s%22 %25 file%0A        # print 'path is file: ', path.isfile(file_path)%0A        if not path.isfile(file_path):%0A            continue%0A        _, ext = path.splitext(file)%0A        file_st = os.stat(file_path)%0A        fm = datetime.fromtimestamp(file_st.st_mtime)%0A        print 'file modified time is', fm.strftime(%22%25Y-%25m-%25d %25H:%25M:%25S%22), fm.microsecond%0A        src_name = file%0A        dest_name = fm.strftime(FILE_NAME_FORMAT) + ext%0A        dest_dir_name = fm.strftime(DIR_NAME_FORMAT)%0A        dest_dir = path.join(output_dir, dest_dir_name)%0A        src_path = path.abspath(path.join(dirname, src_name))%0A        dest_path = path.abspath(path.join(dest_dir, dest_name))%0A        if not path.exists(dest_dir):%0A            os.makedirs(dest_dir)%0A        print 'src is %25s' %25 src_path%0A        print 'dest is %25s' %25 dest_path%0A        tasks.append((src_path, dest_path))%0A    return 0%0A%0A%0Aos.path.walk(start_dir, handler, ())%0Aif tasks:%0A    for src, dest in tasks:%0A        if not path.exists(src):%0A            print %22%25s not exists.%22 %25 src%0A        elif not path.isfile(src):%0A            print %22%25s is not file.%22 %25 src%0A        elif path.exists(dest):%0A            print %22%25s already exists.%22 %25 dest%0A        else:%0A            os.rename(src, dest)%0A            print 'move %25s to %25s' %25 (src, dest)%0A

add photos walker 01