How can I use a for loop to loop the file in a directory?