I'd just keep a list of files that have already been processed and another list of files to be processed.
Proc A) You could have a little routine that will add a file to the "to do" list only if not in the "done" list. This would be easy to test separately.
Proc B) Next you'd want something that takes a file and extracts all the new files from it. Again easy to test.
Next you'd set up a loop that pulls a file from the "to do" list. You don't want to do
foreach file in `cat to_do_list` because you'll be adding new files to the list as you go along.
Call proc B) to get all the files accessed by that file and then use proc A) to add them to the "to do" list if not already in there.
Once a file has been loaded then it goes into the "done" list.
Unsure if that made sense but at least it's easier to read than unformatted shell script written by someone else
Mike