dir: convert dir_add* to take an index