I believe this is exactly doing what you describe.
The script below seems a bit verbose, but a great part of it is taken by the necessary information the user has to give in this somewhat complicated construction.
How to use
As always, copy the script below, enter the appropriate paths, in this case quite a few, the appropriate identifying strings, and save it as reorg.py
.
Run it by the command:
python3 /path/to/reorg.py
The script
#!/usr/bin/env python3
import os
import shutil
# --------------------------------------------------------
# existing files directories
original_dir = "/path/to/original_files"
equals_dir = "/path/to/files_with_name_variants"
# original identifying string
id_string = "code"
# variants + their desired destination
var_1 = "node"; vardir_1 = "/path/to/directory/where_first_variants_shouldbestored"
var_2 = "kode"; vardir_2 = "/path/to/directory/where_second_variants_shouldbestored"
# ---------------------------------------------------------
origs = []
for root, dirs, files in os.walk(original_dir):
for name in files:
if id_string in name:
origs.append(name.replace(id_string, ""))
for root, dirs, files in os.walk(equals_dir):
for name in files:
if var_1 in name:
if name.replace(var_1, "") in origs:
shutil.copyfile(root+"/"+name, vardir_1+"/"+name)
if var_2 in name:
if name.replace(var_2, "") in origs:
shutil.copyfile(root+"/"+name, vardir_2+"/"+name)