fixed handling of empty directories (broken by previous commit)