Last active
November 1, 2015 23:39
-
-
Save K0G0/205de4d8e829443ed41d to your computer and use it in GitHub Desktop.
Advanced FIM - Gather Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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