-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_备份原始图片.py
58 lines (48 loc) · 1.61 KB
/
12_备份原始图片.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from multiprocessing import Manager, Pool
import os
def copyFile(oldFile, newFile, queue=None):
with open(oldFile, 'rb') as f:
content = f.read()
with open(newFile, 'wb') as f:
f.write(content)
if queue is not None:
queue.put(1)
def copyFolder(old, new):
files = os.listdir(old)
pool = Pool(8)
# 待拷贝文件数
n = files.__len__()
queue = Manager().Queue(n)
for file in files:
pool.apply_async(copyFile, (f'{old}\\{file}', f'{new}\\{file}', queue))
pool.close()
# 完成拷贝的文件个数
finish = 0
while finish < n:
finish += queue.get()
rate = int(finish / n * 100)
print('\r', '♦' * int(rate / 5), f'{rate}%', end='')
pool.join()
def main():
backup_name='未缩放备份图片'
if not os.path.exists(backup_name):
os.mkdir(backup_name)
new = backup_name+'/'+word+'(未缩放)'
if os.path.exists(old):
if os.path.isdir(old):
print('第八步:'+word+'文件夹备份中...')
print("------------------------------------------------------------")
copyFolder(old, new)
print("\n------------------------------------------------------------\n\n")
return
copyFile(old, new)
return
print('原文件不存在!')
main()
if __name__ == '__main__':
line_list = []
with open('01_keyword.txt', encoding='utf-8') as file:
line_list = [k.strip() for k in file.readlines()] # 用 strip()移除末尾的空格
for word in line_list:
old = '标准处理图片/' + word
main()