You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1011 B

  1. import os
  2. import os.path as osp
  3. import datetime
  4. from util import no_parents,get_drives
  5. def build(after,*starts):
  6. if isinstance(after,datetime.datetime):
  7. after = after.timestamp()
  8. var_unsubbed = map(osp.expandvars,starts)
  9. abs_paths = map(osp.abspath,var_unsubbed)
  10. starts = list(no_parents(abs_paths))
  11. ret = []
  12. for path in starts:
  13. for root,dirs,files in os.walk(path,topdown=True):
  14. try:
  15. dirs[:] = list(filter(
  16. lambda p: osp.getmtime(osp.join(root,p)) > after,
  17. dirs
  18. ))
  19. ret += [osp.join(root,file) for file in files]
  20. except:
  21. print('Error',root,sep= ': ')
  22. return ret
  23. def build_ext(ext,paths):
  24. ret = {}
  25. for path in paths:
  26. if path.endswith(ext):
  27. name = osp.basename(path)
  28. try:
  29. ret[name].append(path)
  30. except KeyError:
  31. ret[name] = [path]
  32. return ret