Rather than telling the LLM "loop through these files", tell it "write a script to loop through these files", then hard-code that script somewhere.