import os
import shutil
map = {}
target_root = os.path.abspath("E:/gefunden")
with open("scratch/output.txt") as f1:
for db_file in f1:
# print(db_file)
path, filename = os.path.split(db_file)
target_folder = os.path.relpath(path, "/sdcard/WhatsApp")
target_folder = (os.path.join(target_root, target_folder))
# print(target_folder)
map[filename.rstrip()] = {"files": [], "folder": target_folder}
with open("scratch/search.txt") as f2:
for backup_file in f2:
map[os.path.basename(backup_file).rstrip()]["files"].append(backup_file.rstrip())
for filename_entry in map:
target = os.path.join(map[filename_entry]["folder"], filename_entry)
count = 0
for source in map[filename_entry]["files"]:
if count == 0:
# print(target)
pass
else:
# print(target + "_" + str(count))
target = target + "_" + str(count)
count += 1
os.makedirs(os.path.dirname(source), exist_ok=True)
shutil.copy(source, target)
# print(source + " -> " + target)
pass