Can Automator distribute a large number of files into counted subfolders? I would like to build an Automator application that counts the files in the hostfolder, creates a numbered subfolder named &quot; [hostFolder name] [counter] &quot;, moves at maximum 128 files from hostFolder in sequential order into this new subfolder, and loops until all files in hostFolder are sorted into subfolders (i.e. the last subfolder will have fewer than 128 files in it). Before the workflow runs, the hostfolder will always only contain files, no subfolders.
Here's the desired outcome of my ideal workflow using as an example an arbitrary folder containing an arbitrary number of files, also arbitrarily named. (Note I do not need the workflow to rename any files):

A folder named Beans contains 1027 files, the files Legume 0001 to Legume 1027. My Automator application receives the folder Beans as input. Once the workflow has run, the folder Beans now contains 9 subfolders, named Beans 1, Beans 2, Beans 3, and so on all the way to Beans 9.
The subfolder Beans 1 contains files Legume 0001, Legume 0002, Legume 0003, and so on to Legume 0128. The subfolder Beans 2 contains the files Legume 0129 to Legume 0256. In other words, each subfolder contains 128 of the files named Legume **** in sequential order. The only exception is the final subfolder, Beans 9, which contains only 3 files, the files Legume 1025, Legume 1026, and Legume 1027.
This should do what you've asked for. As coded, the only thing you may need to change in the bash script is filesPerSubDir="128" if you want a different file count per subdirectory within the parent directory that's passed to the Run Shell Script action.  

Add a Run Shell Script action to your Automator application/service/workflow and set Shell: /bin/bash and Pass input: as arguments. Remove the default code and then copy and paste the code below into the Automator Run Shell Script action.



#!/bin/bash

filesPerSubDir="128"

for argument in "$@"; do
    if [[ -d $argument ]]; then
        cd "$argument" || exit 1
        dirName="$(basename "$argument")"
        fileCount="$(find . -maxdepth 1 -flags nohidden -type f ! -iname ".*" | awk 'END{print NR}')"
        subDirCount="$(( fileCount / filesPerSubDir + 1 ))"
        for (( i = 1; i &lt; subDirCount+1; i++ )); do
            find . -maxdepth 1 -flags nohidden -type f ! -iname ".*" | head -$filesPerSubDir &gt; .moveList
            if [[ -s  .moveList ]]; then
                mkdir "$dirName $i"
                while IFS= read -r file; do
                    mv "$file" "$dirName $i"
                done &lt; .moveList
            fi
        done
        rm .moveList
    fi
done




The image below shows a testing of the code and the workflow completed successfully as noted by the green circles with the check mark. This is just and example of how to implement the Run Shell Script action, it can be done numerous ways however you just have to pick what method you want to pass the Folders in Finder to it, the rest is done by the script.





The image below shows the code with syntactical highlighting and is included as it helps in reading the code (especially when the code isn't commented, sorry don't have time at the moment).





Note: The bash script is not coded to handle an embedded newline in the name of a filesystem object, which IMO doesn't belong there in the first place! Feel free to modify as needed/wanted to suite your needs, adding/modifying code and or additional error checking if/when wanted/needed. Additionally, this is by no means the only way to code  the script to handle what you want automated but it's what I threw together to get something posted for you. If you have any questions, just ask.