Skip to content

Commit

Permalink
优化代码,office_automation的55行可更改
Browse files Browse the repository at this point in the history
  • Loading branch information
IVEN-CN committed Jan 22, 2024
1 parent 28957eb commit 973ff2a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 21 deletions.
23 changes: 8 additions & 15 deletions office_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')
main(path=r'D:\41shortA2',ifcolordiv=False)
64 changes: 58 additions & 6 deletions renamer/main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -30,17 +45,54 @@ 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:
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)

if '800' in i:
os.rename(k, new_name)
Expand Down

0 comments on commit 973ff2a

Please sign in to comment.