helper: rewrite _scan_dir()