diff --git a/.gitignore b/.gitignore index 7f7cccc..d441544 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ docs/_build/ # PyBuilder target/ +test_*.py \ No newline at end of file diff --git a/build.py b/build.py index 2bce11b..d49f6f6 100644 --- a/build.py +++ b/build.py @@ -1,9 +1,26 @@ import os -from util import get_drives() +import os.path as osp +import datetime +from util import no_parents +from util import get_drives def build(after,*starts): - if starts: - paths = starts - else: - paths = get_drives() - for path in paths: - for root,dirs,files in os.walk( \ No newline at end of file + if isinstance(after,datetime.datetime): + after = after.timestamp() + var_unsubbed = map(osp.expandvars,starts) + abs_paths = map(osp.abspath,var_unsubbed) + starts = list(no_parents(abs_paths)) + ret = [] + for path in starts: + for root,dirs,files in os.walk(path,topdown=True): + try: + dirs[:] = list(filter( + lambda p: osp.getmtime(osp.join(root,p)) > after, + dirs + )) + ret += [osp.join(root,file) for file in files] + except: + print('Error',root,sep= ': ') + return ret +if __name__ == "__main__": + td = datetime.datetime.today() + ret = build(datetime.datetime(td.year,(td.month - 1 -1)%12+1,1),r'X:\Users\Ralphie') \ No newline at end of file diff --git a/update_mtimes.py b/update_mtimes.py new file mode 100644 index 0000000..7032917 --- /dev/null +++ b/update_mtimes.py @@ -0,0 +1,13 @@ +import ctypes +import os +def is_admin(): + return ctypes.windll.shell32.IsUserAnAdmin() != 0 +exe_path = os.path.expandvars(r"%userprofile%\portables" + r"\foldertimeupdate" + r"\FolderTimeUpdate.exe" + ) +def update(*starts,force_admin = True): + if not is_admin() and force_admin: + raise Exception("Process must be admin") + for start in starts: + subprocess.check_call([exe_path,'/stext','null','/BaseFolder',start]) diff --git a/util.py b/util.py index a478222..5b3a19d 100644 --- a/util.py +++ b/util.py @@ -1,5 +1,7 @@ from ctypes import windll -#https://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python u=RichieHindle +import os +#https://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python +#u=RichieHindle def get_drives(): uppercase = map(chr,range(ord('A'),ord('A')+26)) drives = [] @@ -12,14 +14,16 @@ def get_drives(): return drives def no_parents(paths): - paths = sorted(paths,key=len) - first = True - ret = [] - while len(paths) > 0: - el1 = old_paths[0] - old_paths = paths[1:] - paths = [] - for path in old_paths: - if not paths.startswith(el1): - paths.insert(0,path) + paths = sorted(paths,key=len) + ret = [] + paths + while len(paths) > 0: + el1 = paths[0] + ret.append(el1) + old_paths = paths[1:] + paths = [] + for path in old_paths: + + if not path.startswith(el1): + paths.append(path) return ret \ No newline at end of file