@@ -0,0 +1,1998 @@
+#!/usr/bin/env python3%0A# -*- coding: utf-8 -*-%0A# ZHOU Cheng %3Cc.zhou@live.com%3E%0A# Format image filename to %22IMG_YYYYMMDD_hhmmss_n.jpg%22%0A%0Aimport datetime%0Aimport os%0Aimport sys%0A%0A%0Adef get_image_format_filename(file_path, image_time, file_extension):%0A    file_name = %22IMG_%7B%7D.%7B%7D%22.format(image_time.strftime(%22%25Y%25m%25d_%25H%25M%25S%22), file_extension)%0A    if not os.path.exists(os.path.join(file_path, file_name)):%0A        return file_name%0A    n = 1%0A    while True:%0A        file_name = %22IMG_%7B%7D_%7B%7D.%7B%7D%22.format(image_time.strftime(%22%25Y%25m%25d_%25H%25M%25S%22), n, file_extension)%0A        if not os.path.exists(os.path.join(file_path, file_name)):%0A            return file_name%0A        n += 1%0A%0A%0Adef rename_file_by_time(file_path, old_name, image_time):%0A    file_extension = old_name.rsplit(%22.%22, 1)%5B-1%5D%0A    new_name = get_image_format_filename(file_path, image_time, file_extension)%0A    os.rename(os.path.join(file_path, old_name), os.path.join(file_path, new_name))%0A    print(%22%7B%7D %E9%87%8D%E5%91%BD%E5%90%8D%E6%88%90 %7B%7D%22.format(old_name, new_name))%0A%0A%0Adef format_image_filename(file_path, file_name):%0A    image_path = os.path.join(file_path, file_name)%0A    if not os.path.isfile(image_path):%0A        print(%22%7B%7D %E4%B8%8D%E5%AD%98%E5%9C%A8%22.format(image_path))%0A        return%0A    elif file_name.startswith(%22IMG_%22):%0A        print(%22%7B%7D %E4%B8%8D%E9%9C%80%E8%A6%81%E8%BD%AC%E5%8C%96%22.format(file_name))%0A        return%0A    elif file_name.startswith(%22wx_camera_%22):%0A        timestamp = int(file_name%5B10:20%5D)%0A        image_time = datetime.datetime.fromtimestamp(timestamp)%0A        rename_file_by_time(file_path, file_name, image_time)%0A        return%0A    elif file_name.startswith(%22mmexport%22):%0A        timestamp = int(file_name%5B8:18%5D)%0A        image_time = datetime.datetime.fromtimestamp(timestamp)%0A        rename_file_by_time(file_path, file_name, image_time)%0A        return%0A    return%0A%0Aif __name__ == '__main__':%0A    dir_path = sys.argv%5B1%5D%0A    if len(sys.argv) %3C 2 or (not os.path.isdir(sys.argv%5B1%5D)):%0A        print(%22%E9%9C%80%E8%A6%81%E4%BC%A0%E5%85%A5%E5%9B%BE%E7%89%87%E7%9B%AE%E5%BD%95%22)%0A        exit()%0A    for filename in os.listdir(sys.argv%5B1%5D):%0A        format_image_filename(sys.argv%5B1%5D, filename)%0A

add format image file scripts