toolkit / love_huggingface.py
k4d3's picture
more renames
dd352bf
#!/usr/bin/env python
import os
import shutil
import sys
# Get the source directory from terminal input
if len(sys.argv) != 2:
print("Usage: python script.py <source_directory>")
sys.exit(1)
source_dir = sys.argv[1]
base_dir_name = os.path.basename(source_dir.rstrip('/'))
target_dir1 = os.path.join(source_dir, f'{base_dir_name}1')
target_dir2 = os.path.join(source_dir, f'{base_dir_name}2')
# Create the target directories if they don't exist
os.makedirs(target_dir1, exist_ok=True)
os.makedirs(target_dir2, exist_ok=True)
# Get a list of all files in the source directory
files = os.listdir(source_dir)
# Dictionary to keep track of which files have been moved
moved_files = {}
# Iterate over each file in the source directory
for file in files:
# Skip directories
if os.path.isdir(os.path.join(source_dir, file)):
continue
# Get the base filename (without extension)
base_filename = os.path.splitext(file)[0]
# Determine the target directory based on whether the base filename has been seen before
if base_filename not in moved_files:
target_dir = target_dir1 if len(moved_files) % 2 == 0 else target_dir2
moved_files[base_filename] = target_dir
else:
target_dir = moved_files[base_filename]
# Move the file to the appropriate target directory
shutil.move(os.path.join(source_dir, file), os.path.join(target_dir, file))
print("Files have been separated into two directories.")