There is a script that deletes files using a temporary stamp. Deletion with recursion clears nested directories. After the script, empty directories remain. Tell me how else to delete and cleaned directories.
import os import datetime for dirpath, dirnames, filenames in os.walk(r'C:\py\dir_for_remove'): for file in filenames: curpath = os.path.join(dirpath, file) file_modified = datetime.datetime.fromtimestamp(os.path.getmtime(curpath)) if datetime.datetime.now() - file_modified > datetime.timedelta(minutes=5): os.remove(curpath)