The goal of this script is to delete all node_modules that haven't been touch in the last 15 days.
It is currently working, but as it goes inside each folder because of os.walk i lose efficiency as i don't have to go inside a node_modules folder because it's exactly what i want to delete
import os
import time
import shutil
PATH = "/Users/wagnermattei/www"
now = time.time()
old = now - 1296000
for root, dirs, files in os.walk(PATH, topdown=False):
for _dir in dirs:
if _dir == 'node_modules' and os.path.getmtime(os.path.join(root, _dir)) < old:
print('Deleting: '+os.path.join(root, _dir))
shutil.rmtree(os.path.join(root, _dir))