Extract name from file in a sensible way