Get dirname from paths to avoid opening files