fix dirname to handle input of form "foo/" correctly