Fix file reading issue, use directory iterator