This logic should probably also be moved to `FileHelpers`.
(How many times do we have code similar to this?)