Use `idx = not is_dir` instead of this?