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 / loop through files usi...
Power Automate
Answered

loop through files using PAD

(0) ShareShare
ReportReport
Posted on by 43

averma_2-1627073097378.png

 

Hi Readers,

 

I am trying to loop though excel files in a folder to update the same content. There are 72 files in total. I can see the files are stored with file numbers in the variable 'files'. Is there a way I can invoke the file number to set up a loop? or any alternative way to loop through files using PAD would be useful please. 

 

Thanks in advance.

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    So, the first command 'Get Files in Folder' already labeled your list as Files.

    When you used Set Variable %NewVar% to Files [0], you are calling NewVar the first file name.  

     

    Your ForEach command needs to be pointed at %Files%...get rid of the Set Variable command.

  • averma Profile Picture
    43 on at

    @MichaelAnnis Thanks for pointing that out MichaelAnnis. Rookie mistake! 🙂 but what I am actually trying to do is to generalise the UI elements. I saw the post by @Anonymous  a.k.a Loop over several Excel files  and was trying to assign a new variable to capture the generic name.

    I tried and currently am failing;

    averma_0-1627121961447.png

    I tried to update the UI element name with and without '-Excel' at the end without success. I also saw your response to another query last a.k.a Perform actions on a specific workbook selected from a file.  where you suggested using * at the end of the common name denominator. Just tried that and its still not working.

    averma_1-1627122318777.png

     

    Any idea where I am going wrong?

  • tkuehara Profile Picture
    667 on at

    Hi @averma 

     

    What exactly is failing? Please check how your title bar is displayed on screen because it can be displayed with and without extension:

    tkuehara_0-1627306414416.png

    In my case (with extension) I only changed the name parameter to:

    tkuehara_1-1627306507020.png

    I also noticed you are in the "Visual editor" mode. Please change it to "Custom":

    tkuehara_3-1627307081916.png

    I did a sample test to open each excel file in a folder and activate the filter option and it worked:

    tkuehara_2-1627306947707.png

     

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    @averma,

     

    I was wrong with the "*"...I will have to fix that on the other post.  My apologies.  In the "Name" box, there is a selector to change from "Equal to" to "Contains", then just leave in the text field only that which is the same in all filenames.

    MichaelAnnis_1-1627311223904.png

     

     

    On your other option, I noticed in the first photo above, %NewVar% was set to Current Item (the file path and name) without extension.  Then %NewVar% is used in your selector "Name=".  I think this is an error, because looking at my default selector below, it is only the name.extension, not the path (note: extension is included):

    MichaelAnnis_0-1627310062894.png

    So, you will need the filename only, which I believe @tkuehara addressed would equal CurrentItem.name.

     

    Best of luck.

     

  • averma Profile Picture
    43 on at

    Hello Guys

     

    @tkuehara Thanks for your reply. I tried both '%CurrentItem.Name% - Excel' and just %CurrentItem.Name% and it didnt work.

    averma_0-1627328492957.pngaverma_1-1627328519074.pngaverma_2-1627328578162.png

    Apparently I tried @MichaelAnnis suggestion of altering it to Contains and use a word just to check and it worked. But I need to be able to use the generic variable for all the files. 

    Also do I need to change the UI element Name as well? I tried and still didn't work though! I have posted snippets in the hopes that you might be able to pick up where I am going wrong.

     

    Kind regards

    Amit

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

    You should not have to do it on the underlying elements.  Elements are created in a tree structure, so all the excel elements (if you found them under the same original workbook) should be managed by that top selector (the window name) which we are trying to troubleshoot.

    Is each file the only excel file open on the computer at any given point in time?  If so, simply uncheck "Name" from the right menu bar.  It is unnecessary information, and the bot will look for the only open Excel window for the selector.  I got it to work here:

    MichaelAnnis_2-1627334442421.png

     

    MichaelAnnis_1-1627334390018.png

    Best of luck.

     

  • averma Profile Picture
    43 on at

    @MichaelAnnis It worked. Gutted though to keep hitting error with generic variable though but your solution helped me move on. Thanks

     

    Kind regards

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