Simplify some file listing code