import os,re,shutil
path = 'E:\\04.AutomationProject'
folder = "E:\\test"
if os.path.exists(folder):
print("目录存在")
else:
os.mkdir("E:\\test")
print("目录创建成功!")
for currentFolder,subFolder,filenames in os.walk(path):
for fileName in filenames:
mo = re.compile('.*\.txt$').search(fileName)#\.txt表示文本类型个,可以更改成\.pdf or \.jpg
if mo == None:
continue
else:
print("%s\%s"%(currentFolder,mo.group()))
fillName = currentFolder + "\\" +mo.group()#拼接文件txt文件的绝对路径
shutil.copy(fillName,"E:\\test")