Run mkdir only if necessary.