123456789101112131415161718192021222324252627282930313233343536 |
- '''
- Author: zeke-chin zeke-chin@icloud.com
- Date: 2022-10-11 16:38:18
- LastEditors: zeke-chin zeke-chin@icloud.com
- LastEditTime: 2022-10-12 17:53:30
- FilePath: /test_script/HR_OCR/tools/suffix.py
- Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- '''
- import os
- from pathlib import Path
- from itertools import chain
- import sys
- target_path = '/Users/zeke/work/sx/OCR/image_data/营业执照90'
- suffix = 'jpg' if len(sys.argv) != 3 else sys.argv[2]
- def get_range(n):
- len_n = len(str(n))
- for num in range(1, n + 1):
- output = str(num)
- while len(output) < len_n:
- output = f'0{output}'
- yield output
- file_paths = list(chain(*[Path(target_path).rglob(f'*.{ext}') for ext in ['jpeg', 'jpg', 'png', 'JPG', 'PNG']]))
- print(len(file_paths))
- num = len(file_paths)
- file_name_list = list(get_range(num))
- for i in range(num):
- file = file_paths[i]
- print(file)
- new = file.parent / f'{file_name_list[i]}_img.{suffix}'
- file.rename(new)
|