Fix so it works for directories too