I'm trying to do that most basic of things: perform one or more commands on all files within a particular folder.
In this instance, it's converting eps files to PDF using macOS's pstopdf command.
#!/bin/zsh
FILES=$(find "/Users/Ben/Pictures/Stock Illustrations" -type f)
for f in "$FILES"
do
echo "$f"
pstopdf "$f"
done
echo "$f" produces a correct list of all the files; but I then get a second list of files -- seemingly from pstopdf itself** -- starting with File name too long: /Users/Ben/Pictures/Stock Illustrations/Flock wallpaper.eps, but the rest of the files are listed correctly.
However, the pstopdf command doesn't create any PDF files.
** I've tried commenting out the echo and the pstopdf command, so I know that each produces a list of filenames.
If I run pstopdf <file.eps> in the Terminal, I get no output to the CLI (e.g. no filename listed), but the file is processed and a PDF file created.
I dare say I could use xargs in the find command, though I prefer the more structured approach of a loop with arguments, not least because it gives the option of multiple commands and other logic, and it's easier to read.
There is a similar question here: I get message "File name too long" when running for..in and touch
But I don't understand how the answer applies. It says "or touch them one by one" (which is what I want), but if I do something like:
FILES=/Users/Ben/Pictures/Stock\ Illustrations/*
I just get "No such file or directory".