I have a Python program where I'm searching through a directory but for certain sub folders in that directory I want to delete files in them if they were created for more than 7 days and the rest of the files in the directory delete if they were created more than 21 days.
So after the local user are company folders and inside that folders are sub folders that I need such as House, Address, And Phone any suggestion?
import os
from datetime import date,timedelta,datetime
import time
#Path for the employee files
path ="C:/inetpub/ftproot/LocalUser/"
#Function to delete the files
def deleteFiles(days,path):
#Set time Value (86400 secs in 24 hours)
current_time = time.time()
time_in_secs = current_time - (days * 86400)
# Check to see if the path exists
if os.path.exists(path):
for root, dirs, files in os.walk(path):
for file in files:
full_path = os.path.join(root,file)
file_status = os.stat(full_path)
#print( full_path)
if(current_time - file_status.st_mtime) // (86400) >= days:
print(full_path)
#os.remove(full_path)
#print(full_path + "\nhas been deleted")
else:
print("Error Path Doesn't Exist!!!!!!!!!!!!")
deleteFiles(7,path)