import os
from pathlib import Path

def get_acronym(folder_name):
    """Generate an acronym from the folder name."""
    # Handle parentheses
    folder_name = folder_name.split('(')[0].strip()
    # Split the name and take first letter of each significant word
    words = folder_name.split()
    acronym = ''.join(word[0].upper() for word in words if len(word) > 2)
    # If acronym would be empty (e.g., all short words), take first letter of first word
    if not acronym and words:
        acronym = words[0][0].upper()
    return acronym

def create_blank_files(folder_path, num_files=50, start_num=1000):
    """Create blank files in the given folder."""
    try:
        # Generate acronym from folder name
        folder_name = folder_path.name
        acronym = get_acronym(folder_name)
        
        # Create blank files
        files_created = 0
        for i in range(num_files):
            number = start_num + i
            file_name = f"{acronym}-M-{number}"  # Removed .txt extension
            file_path = folder_path / file_name
            if not file_path.exists():  # Only create if file doesn't exist
                file_path.touch()
                files_created += 1
        
        print(f"Created {files_created} files in {folder_name}")
        return True
    except Exception as e:
        print(f"Error processing {folder_name}: {str(e)}")
        return False

def process_directory(directory_path=".", num_files=50):
    """Process all folders in the given directory."""
    root_path = Path(directory_path)
    
    # Get all directories in the specified path
    folders = [f for f in root_path.iterdir() if f.is_dir()]
    
    print(f"Found {len(folders)} folders to process")
    
    # Process each folder
    successful = 0
    for folder in folders:
        if create_blank_files(folder, num_files):
            successful += 1
            
    print(f"\nProcessing complete!")
    print(f"Successfully processed {successful} out of {len(folders)} folders")

if __name__ == "__main__":
    import argparse
    
    parser = argparse.ArgumentParser(description='Create blank files in multiple folders')
    parser.add_argument('--dir', default=".", help='Directory containing the folders to process')
    parser.add_argument('--files', type=int, default=50, help='Number of files to create in each folder')
    
    args = parser.parse_args()
    process_directory(args.dir, args.files)
