import shutil
def copy_file(names,old_name,new_name):
for name in names:
filename = name.split("\\")[-1]
#filename:從路徑中截取文件名
shutil.copyfile(old_name + filename, new_name + filename)
files = glob.glob(r'D:/A/1*.txt')
#files : 搜索得到的符合條件(帶有1開頭的txt)的文件列表
old_path = r'D:/A/'
new_path = r'D:/B/'
copy_file(files,old_path,new_path)