web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Retrieving a list of f...
Power Automate
Answered

Retrieving a list of files and reading and writing to them loop help

(0) ShareShare
ReportReport
Posted on by 30

Dear All,

 

I have a script that I am writing that will require loops or something along that list.

 

So right now this script that is attached below reads from a variable and pulls out over 100+ files.  

 

What logic would I need to implement where it reads from each of the files that and then updates each one 1 at time.  Aka like loop?  

 

Does anybody have an example of this or suggestions?

 

PedroNL_0-1673444028478.png

 

I have the same question (0)
  • OkanAutomation Profile Picture
    107 on at

    The loop (for each) should take place after step 6. and before read text.

    So what happens is for every file within TestFiles will follow the activities 7, 8 and 9. The end should be after your last activity.

     

    Although i might see a problem in your flow and that is that in step 7 you try to read text from a path and not the File. You might have to change TestFilesPath to TestFiles (TestFiles is where your Files are?) Or i might have misunderstood these actions. But it seems that the variables within TestFiles is not being used within a read/replace/write activity. 

     

     

     

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    Get Files in Folder (filter for *.ini) to %Files%

    For each %CurrentItem% in %Files%

        Read Text from file

        Replace text

        Write text to file %CurrentItem% "overwrite=yes"

    End (For Each)

     

    Good luck!

  • PedroNL Profile Picture
    30 on at

    @MichaelAnnis @OkanAutomation ,

     

    How would you suggest that I could get an email or save to a file that include the details to the .ini files that were updated?

    Screenshot 2023-02-13 084400.jpg
  • RPGpro Profile Picture
    41 on at

    @MichaelAnnis  wrote:

    Get Files in Folder (filter for *.ini) to %Files%

    For each %CurrentItem% in %Files%

        Read Text from file

        Replace text

        Write text to file %CurrentItem% "overwrite=yes"

    End (For Each)

     

    Good luck!

    To extend that to send the summary email: 

    At the start (before the loop) initialise a text variable, lets call it %emailBody%

    inside the loop, either immediately before or immediately after updating the file, use "append to string variable" to add the current item's name, followed by a <br> (you'll find the current item name in the dynamic content window, I forget the exact name for it), replace <br> with \n or some other form of new line character depending on how your email will be formatted. 

    Then after you've ended the loop, add a new connector to send an email, put the %emailBody% variable in the email body.

     

    A different approach using an array of strings instead of 1 long string: 

    instead of using a string variable, use an array variable, 

    Within the loop, for each modified file, add the current item's name to the array

    after the end of the loop, send the email, you can use the join function within the email body to return each array element with a given delimiter. This will also allow you to do things such count the array elements so that your email subject could for example say "Updated x files out of a total of y files checked" 

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    I think @RPGpro has a good solution. I would just note that within each loop, after replace text, that is saved as %ReplacedText%. So if it’s something you are willing to do per loop, then you could reference that to get the end product. That doesn’t necessarily tell you what was changed. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 247 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 164 Super User 2026 Season 2

#3
trice602 Profile Picture

trice602 138 Super User 2026 Season 2

Last 30 days Overall leaderboard