diff --git a/office_automation.py b/office_automation.py index e56d31e..e152f01 100644 --- a/office_automation.py +++ b/office_automation.py @@ -52,7 +52,7 @@ def main(*num, path, ifcolordiv=True): # num是不需要移动到主图文 pass # 将图片拷贝到主图文件夹 - for i in img_path: + for i in img_path[::2]: shutil.copy(i, os.path.join(path, '主图')) # endregion @@ -64,28 +64,21 @@ def main(*num, path, ifcolordiv=True): # num是不需要移动到主图文 color_div.color_divider.main(path=path, erea='area0.npy') color_div.color_divider.main(path=path, erea='area1.npy') else: - list_path = renamer.main1.get_file_path(path) # 更新list_path - for i in list_path: - if '主图' in i or 'main' in i: - os.remove(i) - + folder_names = ['800X1200', '800X800', '750X1000'] for folder_name in folder_names: folder_path = os.path.join(path, folder_name) - os.makedirs(folder_path, exist_ok=True) - for i in list_path: - if '800' in i: + os.makedirs(folder_path) + for i in img_path: + if '800X1200' in i: shutil.move(i, os.path.join(path, '800X1200')) - elif '1000' in i: + elif '750X1000' in i: shutil.move(i, os.path.join(path, '750X1000')) - elif '1200' in i: + elif '800X800' in i: shutil.move(i, os.path.join(path, '800X800')) else: pass - if __name__ == '__main__': - main(path=r'D:\41short\KC-41-XOU179') - if __name__ == '__main__': - main(path=r'D:\41short\KC-41-XOU179') \ No newline at end of file + main(path=r'D:\41shortA2',ifcolordiv=False) \ No newline at end of file diff --git a/renamer/main2.py b/renamer/main2.py index 4ccbf6d..5607ea0 100644 --- a/renamer/main2.py +++ b/renamer/main2.py @@ -9,18 +9,33 @@ def rename2(path): dir = path path_list = main1.get_file_path(dir) + list_ = [] + list800 = [] + list1000 = [] + list1200 = [] + for i in path_list: - # v = int(i[-6]) # 取括号内的数字 + if '800' in i: + list800.append(i) + elif '1000' in i: + list1000.append(i) + elif '1200' in i: + list1200.append(i) + + list800.sort(key=lambda x: int(re.search(r'\((\d+)\)', x).group(1)), reverse=False) + list1000.sort(key=lambda x: int(re.search(r'\((\d+)\)', x).group(1)), reverse=False) + list1200.sort(key=lambda x: int(re.search(r'\((\d+)\)', x).group(1)), reverse=False) + + for index, i in enumerate(list800[0:5]): k = i match = re.search(r'\((\d+)\)', i) if match is not None: num = match.group(1) else: raise TypeError('没有匹配到括号内的数字') - num_ = int(num) - new_name = re.sub(r'\((\d+)\)', lambda match: f'({int(match.group(1))-5})', i) + new_name = re.sub(r'\((\d+)\)', lambda match: f'({index+1})', i) try: if '800' in i: @@ -30,9 +45,46 @@ def rename2(path): elif '1200' in i: os.rename(k, new_name) except: - list_.append(i) + list_.append((index, i)) - for i in list_: + for index, i in enumerate(list1000[0:5]): + k = i + match = re.search(r'\((\d+)\)', i) + if match is not None: + num = match.group(1) + else: + raise TypeError('没有匹配到括号内的数字') + new_name = re.sub(r'\((\d+)\)', lambda match: f'({index+1})', i) + + try: + if '800' in i: + os.rename(k, new_name) + elif '1000' in i: + os.rename(k, new_name) + elif '1200' in i: + os.rename(k, new_name) + except: + list_.append((index, i)) + + for index, i in enumerate(list1200[0:5]): + k = i + match = re.search(r'\((\d+)\)', i) + if match is not None: + num = match.group(1) + else: + raise TypeError('没有匹配到括号内的数字') + new_name = re.sub(r'\((\d+)\)', lambda match: f'({index+1})', i) + + try: + if '800' in i: + os.rename(k, new_name) + elif '1000' in i: + os.rename(k, new_name) + elif '1200' in i: + os.rename(k, new_name) + except: + list_.append((index, i)) + for index, i in list_: k = i match = re.search(r'\((\d+)\)', i) if match is not None: @@ -40,7 +92,7 @@ def rename2(path): else: raise TypeError('没有匹配到括号内的数字') num_ = int(num) - new_name = re.sub(r'\((\d+)\)', lambda match: f'({int(match.group(1))-5})', i) + new_name = re.sub(r'\((\d+)\)', lambda match: f'({index+1})', i) if '800' in i: os.rename(k, new_name)