[BUGFIX] Ensure valid file path before scanning directory