use one loop in readdir