Eliminate duplicate code in file.recurse

The same piece of code appears a few lines above.
This comes from 9c936d9.
Merge pull request #16513 from dlax/file/drop-copy-paste

Eliminate duplicate code in file.recurse