Write common checks for files in a separate function.