Exclude files beginning with a certain prefix.

Add a feature that allows open_ref to exclude files that contain
a prefix (e.g. "test_" for code that unit tests code snippets).

Also factor out inner loop of get_all_files() to reduce nesting.