forked from jan-di/scan-to-smb1
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwatcher.py
32 lines (26 loc) · 856 Bytes
/
watcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import glob, os, shutil, time, datetime
print('File watcher started')
while True:
i = 0
while True:
i = i + 1
shareEnable = os.getenv('PROXY{}_ENABLE'.format(i))
if shareEnable == None:
break
elif not shareEnable == "1":
continue
shareDirectory = '/share{}'.format(i)
remoteMount = '/remote{}'.format(i)
files = glob.glob(shareDirectory + '/*.*')
for file in files:
_, filename = os.path.split(file)
name, ext = os.path.splitext(filename)
remotePath = remoteMount + "/" + name + ext
try:
print(datetime.datetime.now()," - Move File: '" + file + "' -> '" + remotePath + "'")
shutil.copyfile(file, remotePath)
os.remove(file)
except (FileNotFoundError, OSError) as err:
print("↳ " + str(err))
time.sleep(15)