Python, Deleting all files in a folder older than X days

前端 未结 10 616
无人及你
无人及你 2020-12-08 00:39

I\'m trying to write a python script to delete all files in a folder older than X days. This is what I have so far:

import os, time, sys

path = r\"c:\\user         


        
10条回答
  •  北海茫月
    2020-12-08 00:41

    i did it in more sufficient way

    import os, time
    
    path = "/home/mansoor/Documents/clients/AirFinder/vendors"
    now = time.time()
    
    for filename in os.listdir(path):
        filestamp = os.stat(os.path.join(path, filename)).st_mtime
        filecompare = now - 7 * 86400
        if  filestamp < filecompare:
         print(filename)
    

提交回复
热议问题