-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTransfer.py
More file actions
43 lines (36 loc) · 1.41 KB
/
FileTransfer.py
File metadata and controls
43 lines (36 loc) · 1.41 KB
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
#Program which checks for files which have been modified with the past 24
#hours and copies them to different folder
import os
import datetime
import shutil
def modification_date(filename):
t = os.path.getmtime(filename)
return datetime.datetime.fromtimestamp(t)
def modified_within_day(filename):
if modification_date(filename) + datetime.timedelta(1) >= datetime.datetime.now():
return True
else:
return False
def copy_file(filename, source, destination):
shutil.copyfile(source + filename, destination + filename)
def file_transfer():
source = 'C:/Users/Student/Desktop/AllFiles/'
destination = 'C:/Users/Student/Desktop/RecentFiles/'
source_files = os.listdir(source)
for files in source_files:
if modified_within_day(source + files) == True:
copy_file(files, source, destination)
print 'Moved file: ' + files
def main():
print 'Daily File Transfer Program - runs at 10:30am daily.'
if datetime.datetime.now().time().hour == 10 and \
datetime.datetime.now().time().minute == 30 and \
datetime.datetime.now().time().second == 0:
file_transfer()
else:
answer = raw_input('It is not 10:30am now. Run anyway? y or n: ')
if answer == 'y' or answer == 'Y':
file_transfer()
else:
print 'Goodbye!'
if __name__ == "__main__": main()