import os,shutil
import re
path = 'G:\琴趣科技乐谱\小组完成乐谱的副本'
targetDir = 'G:\输出'
def gci (path):
"""this is a statement"""
parents = os.listdir(path)
for parent in parents:
child = os.path.join(path,parent)
if os.path.isdir(child):
gci(child)
# print(child)
else:
if os.path.splitext(child)[1] == '.sib':
fpath,fname=os.path.split(child)
filename, extension = os.path.splitext(fname)
str = re.sub("[0-9\+\\\!\%\[\]\,\。]", "", filename)
mycopyfile(child,targetDir+"/"+str+".sib")
print(str)
def mycopyfile(srcfile,dstfile):
if not os.path.isfile(srcfile):
print('不是文件')
else:
fpath,fname=os.path.split(dstfile) #分离文件名和路径
if not os.path.exists(fpath):
os.makedirs(fpath) #创建路径
shutil.copyfile(srcfile,dstfile) #复制文件
print('复制完成')
gci(path)
网友评论