I'd like to combine multiple text files, all ending in .txt, into the same document with the filename of each separating the contents of each. I've found ways to combine the contents, I've found ways to combine the filenames, but the closest I've gotten to doing both is the below superuser question, which is exactly what I want, but the comments suggesting how to use the code on MacOS doesn't seem to work, likely because the question is almost a decade old. I'm on mac OS Big Sur 11.2.3.
Update: At the advice of the bot, I've copied and pasted the clarifying details from the previous question posted, as it asked it very succinctly. Here is an example of what I am looking for
* a filename
contents of file
...
* another filename
contents of file
...
etc...
I'm running it through Automator, feeding the files in through "Get Specified Finder Items" and "Get Folder Contents" that then feeds "Run Shell Script" with this script copied below. It says everything runs good, giving 'workflow completed' and no errors, but I don't have 'target-file.org' anywhere.
find -regex '.*\.\(docx?\|org\|rtf\|te?xt\)$' | while read file
do
echo "* $file" >> target-file.org
cat "$file" | pandoc -t org >> target-file.org
done