Fixed a bug when listing directory if not a directory