You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import os
|
|
import shutil
|
|
|
|
|
|
# 将快报下载文件夹的文件,挪到最终保存的文件夹,之后清空下载文件夹
|
|
def move_files(folder_download, folder_all):
|
|
try:
|
|
# 先判断文件夹是否存在
|
|
if not os.path.exists(folder_download):
|
|
os.makedirs(folder_download)
|
|
if not os.path.exists(folder_all):
|
|
os.makedirs(folder_all)
|
|
|
|
# 要转移的文件名
|
|
keywords = ["简版", "日报.zip"]
|
|
|
|
# 遍历源文件夹中的所有文件
|
|
for root, dirs, files in os.walk(folder_download):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
# 检查文件名是否包含任何关键词
|
|
has_keyword = False
|
|
for keyword in keywords:
|
|
if keyword in file:
|
|
has_keyword = True
|
|
break
|
|
|
|
# 如果文件名不包含任何关键词,则移动文件
|
|
if not has_keyword:
|
|
shutil.move(file_path, os.path.join(folder_all, file))
|
|
print(f"已移动文件: {file_path} 到 {folder_all}")
|
|
|
|
except Exception as e:
|
|
print(f"发生错误: {e}")
|