Use pathinfo instead of strinfg operations to get file extension