import os
import shutil
path = "./test/" # 文件夹目录
newpath = ".\\all_file\\"
def read_fileLists(path):
#获得当前路径下所有文件
dirList = os.listdir(path)
for f in dirList:
#获得目录下文件的绝对路径
file = os.path.join(path,f)
#判断该文件是否是目录类型
if not(os.path.isdir(file)):
a,b=f.split(".") #a为文件名,b为文件后缀
oldname = file
newname = newpath + a + "."+b
shutil.copyfile(oldname,newname)
else:
# 是就进行递归,继续寻找该当前文件夹的子文件
read_fileLists(file)
read_fileLists(path)