-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilewatcher.py
More file actions
41 lines (36 loc) · 959 Bytes
/
filewatcher.py
File metadata and controls
41 lines (36 loc) · 959 Bytes
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
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
#Copyright (c) 2013 Tim Davies
#Released under the MIT licence
import os
import settings
import time
import shutil
for d in settings.directories:
contents = os.listdir(d)
files = []
dirs = []
for i in contents:
if "~" in i:
continue
p = os.path.join(d, i)
if os.path.isdir(p):
dirs.append(p)
else:
files.append(p)
for f in files:
bd = f+settings.extension
if not bd in dirs:
os.mkdir(bd)
mtime = os.path.getmtime(f)
ts = time.strftime("%Y-%m-%d-%H%M", time.gmtime(mtime))
e = f.split(".")[-1]
ss = ".".join([ts, e])
if not ss in os.listdir(bd):
shutil.copyfile(f, os.path.join(bd, ss))
print "Backed up %s"%f
else:
print "%s unchanged"%f
# root, dirs, files = os.walk(d)
# print root
# print dirs
# print files