代码如下:
def zip_file(old_path,new_path):
if get_file_count(old_path) >= 10:
for root, dirs, files in os.walk(old_path):
for i in range(len(files)):
# print(files[i])
if (files[i][-4:] == '.log')or (files[i][-5:] == '.html'):
file_path = old_path + files[i]
# print(file_path)
new_file_path = new_path #+ files[i]
# print(new_file_path)
try:
shutil.move(file_path, new_file_path)
logger.info("{a}条剪切成功!".format(a=i))
except Exception as e:
logger.info("剪切失败:{a}".format(a=e))
else:
print("文件少于10条,不需要剪切!")
PS:shutil.move() # 剪切文件;shutil.copy() # 拷贝文件
网友评论