-
Notifications
You must be signed in to change notification settings - Fork 51
/
copy.py
31 lines (27 loc) · 965 Bytes
/
copy.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
import os,shutil
import xlrd
def copy():
rootdir='./'
newdir='../../Desktop/pySpider'
if not os.path.exists(newdir):
os.mkdir(newdir)
list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
for i in range(0,len(list)):
print(list[i])
# try:
path1 = os.path.join(rootdir,list[i])
# except:
# continue
if list[i].endswith('.py'):
shutil.copyfile(path1,os.path.join(newdir,list[i]))
# break
if os.path.isdir(path1):
dir=os.path.join(newdir,list[i])
if not os.path.exists(dir):
os.mkdir(dir)
list1 = os.listdir(path1)
for j in range(0,len(list1)):
path2=os.path.join(path1,list1[j])
if list1[j].endswith('.py'):
shutil.copyfile(path2,os.path.join(dir,list1[j]))
copy()