根据匹配符号复制文件

copy files based on matching symbol

我有一个包含数千个的目录 files.However 我有一个包含同一目录文件名的列表。我想复制列表末尾带星号 * 的文件。

列表是

2016-05-23-0145-30S.INMME_012*
2016-07-12-0546-26S.INMME_006
2016-07-17-2033-16S.INMME_003
2016-07-19-1307-57S.INMME_003
2016-08-17-1649-12S.INMME_006*
2016-09-03-1151-03S.INMME_003
2016-10-21-1240-02S.INMME_006*
2016-10-21-1310-38S.INMME_006
2016-10-23-0016-39S.INMME_006
2016-10-23-0859-50S.INMME_006

所以我想复制2016-05-23-0145-30S.INMME_012* 2016-08-17-1649-12S.INMME_006* 2016-10-21-1240-02S.INMME_006*到单独的目录。

import os
import shutil
def copy_file_to_another_location(inputpath, outputpath, filename):
   if not os.path.exists(outputpath):
      os.makedirs(outputpath)
   shutil.copy(str(os.path.join(inputpath, filename)).replace("\n", "").replace("*", ""), str(os.path.join(outputpath, filename)).replace("\n", "").replace("*", ""))
   print("Copying: " + str(os.path.join(inputpath, filename)).replace("\n", ""))

inputpath = r'C:\Users\me\Desktop\tada\in'
outputpath = r'C:\Users\me\Desktop\tada\out'
file = open("asd.txt", "r", encoding="utf-8")
files_list = file.readlines()
for file in files_list:
   if "*" in str(file):
      copy_file_to_another_location(inputpath, outputpath, file)

注意:此脚本将确保从输入位置到输出位置保持文件夹结构(例如:inputlocation/some_folder/2016-10-23.... 将被复制到 outputlocation/some_folder/2016-10-23...