import os
import random
import json
def process_large_folder(root_folder):
for folder_name, subfolders, filenames in os.walk(root_folder):
for subfolder in subfolders:
subfolder_path = os.path.join(folder_name, subfolder)
for file in os.listdir(subfolder_path):
if file.endswith(".txt"):
file_path = os.path.join(subfolder_path, file)
with open(file_path, 'r', encoding="utf-8") as f:
content = f.read()
if any(keyword in content for keyword in ['该用户觉得商品很好,给出了5星好评',
'该用户未填写文字评价。',
'骗人',
'不要买']):
f.close() # 关闭文本文件
os.remove(file_path) # 删除文本文件
with open(os.path.join(subfolder_path, '首次评论.txt'), 'w', encoding="utf-8") as new_file:
random_comment = random.choice([
'不错,非常满意,性价比已经非常高,还会回购',
'味道不错、非常的好听、吃完这一箱、断续下单。',
'包装好,日期新,打开冲泡香味十足',
'牛肉烩面,好吃不贵,味道好极了,很受欢迎。',
'物有所值,值得购买',
'正宗河南烩面味道真不错',
'味道好,面有嚼劲,进度好,尝了一下可口与超市一样。',
])
new_file.write(random_comment)
# 使用示例
root_folder = input('请输入路径:')
process_large_folder(root_folder)
daima
最新推荐文章于 2024-07-19 00:08:02 发布