Add Scans
Watch a given directory for changes and print out the file list difference
This commit is contained in:
parent
0d8dac8ab9
commit
e2669dd265
42
scans/scans.py
Normal file
42
scans/scans.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from os import listdir
|
||||||
|
from os.path import isfile, join
|
||||||
|
import time
|
||||||
|
|
||||||
|
watch_directory = '/Users/alexanderh/watch_folder'
|
||||||
|
pollTime = 10
|
||||||
|
|
||||||
|
|
||||||
|
def list_files(path):
|
||||||
|
return [f for f in listdir(path) if isfile(join(path, f))]
|
||||||
|
|
||||||
|
|
||||||
|
def listComparison(OriginalList: list, NewList: list):
|
||||||
|
differencesList = [x for x in NewList if x not in OriginalList]
|
||||||
|
return differencesList
|
||||||
|
|
||||||
|
|
||||||
|
def fileWatcher(watch_directory: str, pollTime: int):
|
||||||
|
while True:
|
||||||
|
if 'watching' not in locals():
|
||||||
|
previousFileList = list_files(watch_directory)
|
||||||
|
watching = True
|
||||||
|
print('First Time')
|
||||||
|
print(previousFileList)
|
||||||
|
|
||||||
|
time.sleep(pollTime)
|
||||||
|
|
||||||
|
newFileList = list_files(watch_directory)
|
||||||
|
|
||||||
|
fileDiff = listComparison(previousFileList, newFileList)
|
||||||
|
previousFileList = newFileList
|
||||||
|
if len(fileDiff) == 0:
|
||||||
|
continue
|
||||||
|
notify_new_files(fileDiff)
|
||||||
|
|
||||||
|
|
||||||
|
def notify_new_files(fileDiff: list):
|
||||||
|
print(fileDiff)
|
||||||
|
|
||||||
|
|
||||||
|
# print(list_files('/Users/alexanderh/ahosking_git/python-tools'))
|
||||||
|
fileWatcher(watch_directory, pollTime)
|
Loading…
Reference in New Issue
Block a user