|
import os |
|
import shutil |
|
|
|
|
|
dirs = { |
|
'image': 'jpg', |
|
'image-parse-v3': 'png', |
|
'cloth': 'jpg', |
|
'cloth-mask': 'jpg' |
|
} |
|
spare_dir = 'spare' |
|
|
|
|
|
os.makedirs(spare_dir, exist_ok=True) |
|
|
|
|
|
def get_base_names(dir_path, ext): |
|
return {os.path.splitext(f)[0] for f in os.listdir(dir_path) if f.endswith('.' + ext)} |
|
|
|
|
|
base_names = {} |
|
for dir_name, ext in dirs.items(): |
|
base_names[dir_name] = get_base_names(dir_name, ext) |
|
|
|
|
|
spare_files = set() |
|
for dir_name, names in base_names.items(): |
|
|
|
other_dirs = set(dirs.keys()) - {dir_name} |
|
for base_name in names: |
|
if not all(base_name in base_names[other_dir] for other_dir in other_dirs): |
|
spare_files.add((dir_name, base_name + '.' + dirs[dir_name])) |
|
|
|
|
|
for dir_name, file_name in spare_files: |
|
src = os.path.join(dir_name, file_name) |
|
dst = os.path.join(spare_dir, file_name) |
|
shutil.move(src, dst) |
|
print(f"Moved {src} to {dst}") |
|
|
|
print("Operation completed.") |
|
|