Skip to content

Instantly share code, notes, and snippets.

@K0G0
Last active November 1, 2015 23:39
Show Gist options
  • Select an option

  • Save K0G0/205de4d8e829443ed41d to your computer and use it in GitHub Desktop.

Select an option

Save K0G0/205de4d8e829443ed41d to your computer and use it in GitHub Desktop.
Advanced FIM - Gather Files
import os,hashlib,time
monitor=[
{'path':'E:\Dropbox\SVL\Projects\AdvancedFIM_GatherFiles','recursive':True},
{'path':'E:\Dropbox\SVL\Projects','recursive':False},
{'path':'E:\Dropbox\SVL\Projects\BasicFIM\BasicFIM.py','recursive':False}
]
files={}
def getFiles():
filesList=[]
for x in monitor:
if os.path.isdir(x['path']):
if x['recursive']:
filesList.extend([os.path.join(root, f) for (root, dirs, files) in os.walk(x['path']) for f in files])
else:
filesList.extend([item for item in os.listdir(x['path']) if os.path.isfile(item)])
elif os.path.isfile(x['path']):
filesList.append(x['path'])
return filesList
while True:
for file in getFiles():
hash = hashlib.md5()
with open(file) as f:
for chunk in iter(lambda: f.read(2048), ""):
hash.update(chunk)
md5 = hash.hexdigest()
if file in files and md5 <> files[file]:
print '%s\t%s has been changed!'%(time.strftime("%Y-%m-%d %H:%M:%S") , file)
files[file]=md5
time.sleep(1)
import os
monitor=[
{'path':'E:\Dropbox\SVL\Projects\AdvancedFIM_GatherFiles','recursive':True},
{'path':'E:\Dropbox\SVL\Projects','recursive':False},
{'path':'E:\Dropbox\SVL\Projects\BasicFIM\BasicFIM.py','recursive':False}
]
def getFiles():
filesList=[]
for x in monitor:
if os.path.isdir(x['path']):
if x['recursive']:
filesList.extend([os.path.join(root, f) for (root, dirs, files) in os.walk(x['path']) for f in files])
else:
filesList.extend([item for item in os.listdir(x['path']) if os.path.isfile(item)])
elif os.path.isfile(x['path']):
filesList.append(x['path'])
return filesList
print getFiles()
monitor=[
{'path':'E:\Dropbox\SVL\Projects\AdvancedFIM_GatherFiles','recursive':True},
{'path':'E:\Dropbox\SVL\Projects','recursive':False},
{'path':'E:\Dropbox\SVL\Projects\BasicFIM\BasicFIM.py','recursive':False}
]
for (root, dirs, files) in os.walk(x['path']):
for f in files:
filesList.append(os.path.join(root, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment