Browse Source

build function done, added functionality to call recursive mtime updater

master
Raphael Roberts 7 years ago
parent
commit
5bdcc66772
  1. 1
      .gitignore
  2. 31
      build.py
  3. 13
      update_mtimes.py
  4. 26
      util.py

1
.gitignore

@ -58,3 +58,4 @@ docs/_build/
# PyBuilder
target/
test_*.py

31
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(
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')

13
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])

26
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
Loading…
Cancel
Save