changed dir to dirpath (shadowed builtin)