43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
|
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)
|