创建文件夹
# -- coding: utf-8 --
import os
import time
import os
def create(addr):
for i in range(1, 100): #范围是你需要的数字范围,我创建的是名为1~100的文件夹
os.makedirs(addr+'/'+str(i)) #str(i)前后可加你需要的前缀和后缀
time.sleep(2)
addr = 'C:/Users/YYQ/Desktop/img'#你需要创建文件夹的目录
create(addr)
定时删除文件夹里的内容
# -- coding: utf-8 --
import os
import shutil
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
img_path = "C:/Users/YYQ/Desktop/img"
def run_task(filepath):
del_list = os.listdir(filepath)
for f in del_list:
file_path = os.path.join(filepath, f)
if os.path.isfile(file_path):
os.remove(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
@sched.scheduled_job('cron', day_of_week='*', hour='*', minute='*', second='*/5')
def scheduled_job():
run_task(img_path)
if __name__ == '__main__':
sched.start()
# 每隔5秒
@sched.scheduled_job('cron', day_of_week='*', hour='*', minute='*', second='*/5')
# 每隔5分钟 0秒
@sched.scheduled_job('cron', day_of_week='*', hour='*', minute='*/5', second='0')