forked from chenguohui/AutomatePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy.py
More file actions
22 lines (19 loc) · 662 Bytes
/
Copy pathcopy.py
File metadata and controls
22 lines (19 loc) · 662 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import sys
import shutil
def copy(suffix, src, dst):
# Create dst directory
if not os.path.exists(dst):
os.mkdir(dst)
# list all files
try:
for dirpath, dirnames, filenames in os.walk(src):
#print(dirpath, dirnames, filenames)
for filename in filenames:
if filename.endswith('.'+suffix):
print(os.path.join(dirpath, filename))
# copy files with pointed suffix to dst
shutil.copy(os.path.join(dirpath, filename), dst)
except shutil.SameFileError:
print("Finished copying file.")
copy('py', '.', 'pyfiles')