import os import shutil # Automatically get the directory where the script is located source_dir = os.path.dirname(os.path.abspath(__file__)) archive_dir = os.path.join(source_dir, "TMP") # Define valid hex digits in uppercase hex_digits = "0123456789ABCDEF" # Create subfolders (0-9 and A-F) inside the ARCHIVE folder if they don't exist for digit in hex_digits: folder_path = os.path.join(archive_dir, digit) os.makedirs(folder_path, exist_ok=True) # Iterate over each file in the ARCHIVE folder for filename in os.listdir(archive_dir): # Process only zip files that match the expected naming pattern if filename.endswith(".zip"): # Convert the first character of the filename to uppercase first_digit = filename[0].upper() if first_digit in hex_digits: source_file = os.path.join(archive_dir, filename) dest_file = os.path.join(archive_dir, first_digit, filename) print(f"Moving {filename} to folder {first_digit}/") shutil.move(source_file, dest_file) else: print(f"Skipping file {filename}: first character '{filename[0]}' is not a valid hex digit.")