In what way, exactly, is it "failing on the succeeding loops?" What are the file-names in question? (Do any of them, for instance, contain spaces?) As usual, the devil is in the details. Show us a few of the filenames and give the exact error messages that you are seeing.