copy/extract_files_by_name
import os
import shutil
def CreateDir(path):
isExists=os.path.exists(path)
# 判断结果
if not isExists:
# 如果不存在则创建目录
os.makedirs(path)
print(path+' 目录创建成功')
else:
# 如果目录存在则不创建,并提示目录已存在
print(path+' 目录已存在')
if __name__ == "__main__":
input_path = input("输入文件存放目录:(E:...\...)")
make_path = input_path + input("在该目录下创建文件夹:(\...)")
CreateDir(make_path)
file_lists = os.listdir(input_path)
# print(file_list)
for list in file_lists:
if 'cti' in list:
# print(list)
# list 复制到 make_path
# print(input_path + '\\' + list)
# print(make_path + '\\' + list)
if os.path.isfile(input_path + '\\' + list):
oldFile = input_path + '\\' + list
newFile = make_path + '\\' + list
shutil.copyfile(oldFile,newFile)