import os
import shutil
def take_samefile(or_path, tar_path, tar_type):
tar_path = tar_path
if not os.path.exists(tar_path):
os.makedirs(tar_path)
path = or_path
files = os.listdir(path) # 讀取or_path文件列表
for file in files:
file_type = str(file).split('.')[1] # 讀取文件后綴
if file_type == tar_type:
print("take{}from{}".format(file, files))
dir = path + '/' + file # 存儲文件路徑
deter = tar_path + '/' + str(file)
shutil.copyfile(dir, deter)
if __name__ == "__main__":
take_samefile(r"", r"", "")