python中os.remove可递归删除指定目录和文件:

import os
import time
dirPath=r"D:\ftp"
while True:
    for root, dirs, files in os.walk(dirPath, topdown=False):
        for name in files:
            os.remove(os.path.join(root, name))
            print("%s文件删除成功 %s" % (name,(time.strftime("%d/%m/%Y%H:%M:%S"))))
        for name in dirs:
            os.rmdir(os.path.join(root, name))
            print("%s子文件夹下文件删除成功 %s" % (name,(time.strftime("%d/%m/%Y%H:%M:%S"))))
    time.sleep(3600)

运行结果:

python定时删除指定路径下目录及文件

参考文献:https://blog.csdn.net/muwinter/article/details/77196261 

相关文章:

  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2021-11-02
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
相关资源
相似解决方案