-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyDirTree.py
49 lines (42 loc) · 1.38 KB
/
CopyDirTree.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
49
import os
import shutil
import sys
def _copy(ffile,tfile):
isfe = os.path.exists(ffile)
if not isfe:
print "can not find : "+ffile
return
if os.path.exists(tfile):
fst = os.stat(ffile)
tst = os.stat(tfile)
if fst.st_size==tst.st_size:
if abs(fst.st_mtime==tst.st_mtime)>0.01:
shutil.copy2(ffile,tfile)
else:
shutil.copy2(ffile,tfile)
else:
shutil.copy2(ffile,tfile)
def copyDir(src,tar):
src = os.path.normpath(src)
tar = os.path.normpath(tar)
if os.path.exists(src):
if not os.path.exists(tar):
os.makedirs(tar)
if os.path.exists(tar):
for parent,dirnames,filenames in os.walk(src):
for dirname in dirnames:
_p = parent[len(src)+1::]
_parent = tar+"/"+_p
_dn = os.path.join(_parent,dirname)
if not os.path.exists(_dn):
os.makedirs(_dn)
for filename in filenames:
_p = parent[len(src)+1::]
_parent = tar+"/"+_p
_copy(os.path.join(parent,filename),os.path.join(_parent,filename) )
if __name__=="__main__":
argv = sys.argv
if len(argv)>2:
copyDir(argv[1],argv[2])
else:
print "input error!"