记事本格式
import os
def copy(src_file, dst_file):
import shutil
# 执行复制操作
shutil.copy2(src_file, dst_file)
def main(parent,data,dest_path):
_list = []
for line in open(data, encoding="utf-8"):
line = line.strip()
_list.append(line.split("\t"))
print(_list)
def get_all_path(dirname, filter_set=None):
if filter_set is None:
filter_set = set()
paths = [(root, file, os.path.join(root, file))
for root, dirs, files in os.walk(dirname)
for file in files
if not any(item in os.path.abspath(os.path.join(root, file)) for item in filter_set)]
return paths
files = get_all_path(parent)
for v1, v2, v3 in files:
for item in _list:
print(item[1])
if item[0] in v2 and item[1] in v2 :
copy(v3, os.path.join(dest_path, v2))
# date.txt
data = r'C:\Users\Administrator\Desktop\data.txt'
# 父文件夹
parent = r'C:\Users\Administrator\Desktop\1'
# 复制到
dest_path = r'C:\Users\Administrator\Desktop\2'
# os.mkdir(dest_path)
# 创建文件夹(如果不存在),跳过创建如果已存在
os.makedirs(dest_path, exist_ok=True)
main(parent,data,dest_path)