3v324v23's picture
first latest
7bdf62a
raw
history blame
1.26 kB
import os
import shutil
# Directories configuration
dirs = {
'image': 'jpg',
'image-parse-v3': 'png',
'cloth': 'jpg',
'cloth-mask': 'jpg'
}
spare_dir = 'spare'
# Ensure the spare directory exists
os.makedirs(spare_dir, exist_ok=True)
# Function to get base names of files in a directory
def get_base_names(dir_path, ext):
return {os.path.splitext(f)[0] for f in os.listdir(dir_path) if f.endswith('.' + ext)}
# Collect base names from all directories
base_names = {}
for dir_name, ext in dirs.items():
base_names[dir_name] = get_base_names(dir_name, ext)
# Identify files without a match in all directories
spare_files = set()
for dir_name, names in base_names.items():
# Find files that do not have a match in every other directory
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]))
# Move spare files to the spare directory
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.")