fixed invalid logic with empty directory