-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (39 loc) · 1.36 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/env python
# -*- coding: utf8 -*-
# this can copy source folder newest "one" file to target folder :D
# made by Mics
# file name: main.py
from os import listdir
from os.path import isdir, isfile, join, getmtime, exists
from shutil import copyfile
SOURCE_FOLDER = "/Users/Mics/test/source"
TARGET_FOLDER = "/Users/Mics/test/target"
DEBUG = True
def debugmsg(string):
if DEBUG: print string
if __name__ == '__main__':
if not isdir(SOURCE_FOLDER):
print "資料夾設定錯誤"
exit()
if not isdir(TARGET_FOLDER):
print "資料夾設定錯誤"
exit()
files = [ f for f in listdir(SOURCE_FOLDER) \
if isfile(join(SOURCE_FOLDER,f)) ]
debugmsg("files: %s" % files)
newest_f = files.pop()
debugmsg("first var newest_f is : %s" % newest_f)
for f in files:
if getmtime(join(SOURCE_FOLDER, f)) > \
getmtime(join(SOURCE_FOLDER, newest_f)):
newest_f=f
debugmsg("newest_f is changed, name is : %s" % newest_f)
debugmsg("last newest_f is : %s" % newest_f)
target_file = join(TARGET_FOLDER,newest_f)
source_file = join(SOURCE_FOLDER,newest_f)
if exists(target_file):
print "target file is exists, copy cancel. (file name: %s)" % \
target_file
exit()
copyfile( source_file , target_file)
print "file copied"