Refactor the code of getting file list