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 / PA desktop - Renaming ...
Power Automate
Unanswered

PA desktop - Renaming Files by reading names from Excel worksheet - Problem

(0) ShareShare
ReportReport
Posted on by 21

PA Desktop Community,

 

I'm looking for some assistance with an error message that I'm getting.  I'm trying to rename several hundred files that I have to download monthly.  Each file comes from a specific customer site.  When the file is downloaded there is no customer identifier on the download.  I need to rename the client's file with their customer identifier that is located in a Excel spreadsheet.  I believe I'm close to having the flow created but I'm getting and error on one of the steps (File to rename not found).  The file in the file folder will always correspond to the first row in the excel spreadsheet then file two with row two in the excel spreadsheet and so on.  I'm attaching my current flow via screenshot.  Any help with troubleshooting this issue would be greatly appreciated.  I did not see this issue identified in the forum so I imagine someone in the future will have the same issue. 

Thanks in advance I truly appreciate the support. 

 

Owen H 

 

Error Message .pngHow I have the Rename File set up.png

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @ohostetler1 

     

    The reason for the action failure is because in rename file action, in file to rename field you are passing the folder name instead of file name 

    Nived_Nambiar_0-1695928203369.png

     

    It expects file name or list of file names to be renamed 

     

    Ok i did not understand how the file name to be renamed, like how flow can determine for the file , where its rename details are present in which row? is there any lookup value like file name for that ?

     

     

     

     

  • ohostetler1 Profile Picture
    21 on at

    Nived,

     

    Good day, that is a great point I guess my thought was that I was trying to rename the files found in the folder (C:\Users\ohost\OneDrive\Desktop\Test Folder).  My question would be what command would tell PA to rename the files found in that folder if not command # 5.  In short the files that are found in this folder need to be renamed (file 1 would have Cell A2 from my excel spreadsheet added to the front of the file name found in the folder).  File 2 would have Cell A2 and so on.  Is there an additional command that I need to add before comannd five that would tell PA to look in this folder to find the files?

     

    Thanks again for reaching out. 

     

    Owen H

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    @ohostetler1 wrote:

    Nived,

     

    Good day, that is a great point I guess my thought was that I was trying to rename the files found in the folder (C:\Users\ohost\OneDrive\Desktop\Test Folder).  My question would be what command would tell PA to rename the files found in that folder if not command # 5.  In short the files that are found in this folder need to be renamed (file 1 would have Cell A2 from my excel spreadsheet added to the front of the file name found in the folder).  File 2 would have Cell A2 and so on.  Is there an additional command that I need to add before comannd five that would tell PA to look in this folder to find the files?

     

    Thanks again for reaching out. 

     

    Owen H


    Hi Owen 

     

    Could you confirm whether the above line means file 2 name should be taken from cell A3 ?

     

    Also is the file name is file name1 format or in different ?

     

    Because the only confusion or blocker is how the bot should determine which file to be renamed, is there any way by which file should be selected for renaming ?

     

     

  • ohostetler1 Profile Picture
    21 on at

    Nived,

    Good morning, I think sometimes a picture says a thousand words I have attached the entire flow (since it's small) I have opened each step to show how I set it up as well as what the excel and files that need to be renamed look like.  I think the main issue here is that none of the steps tell the bot what folder needs to be opened to get to the data that needs to be renamed.  I originally had that folder path in step 5 (C:\Users\ohost\OneDrive\Desktop\Test Folder) but your earlier feedback was that it should not be in that step.  I hope this Word document clearly shows where my error is.  I want to thank you again for taking time out of your schedule to assist.  This back and forth is really helping with my education which I thank you for. 

     

    Owen 

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @ohostetler1 

     

    Flow needs to be like this :

     

    Nived_Nambiar_0-1696008397819.png

     

    Rest of steps are same except how the file is renamed , see below for rename action details

    Nived_Nambiar_1-1696008443464.png

     

    The file would be appended with %text2add%- before filename so that file name looks like as expected

     

    Also still the doubt regarding the file selection is not clear, may be now i can explain with example since we have data now.

     

    My question regarding the file selection , how the bot should decide which text should be added to which filename?

    Example: file 7456_2308.pdf is added with text ty3432, but how it is decided, can we add the other text like X1452 etc?

     

    Hope now its clear for you 🙂

     

     

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    I would preferably recommend reading the data into Excel first, then closing Excel, and then looping through files. This will prevent an Excel session from being left open in case the flow fails when renaming files. It will also be more efficient.

     

    The Excel part should look like this:

    Agnius_0-1696010577969.png

     

    It will get the end of the range dynamically and read it all into a data table. Then it will close Excel, but the data will be stored in the variable.

     

    The renaming part will then look like this:

    Agnius_1-1696010627337.png

     

    Note: For this to work, you need to have at least the same number of items (or more) in Excel as the number of files you have. If there are more files than rows in Excel, this will error out, so you might want to handle that.

     

    Here's a code snippet you can copy and paste directly into PAD to create all those actions for you:

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\ohost\\OneDrive\\Desktop\\Test doc 1.xlsx''' Visible: False ReadOnly: True Instance=> ExcelInstance
    Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
    Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    Excel.CloseExcel.Close Instance: ExcelInstance
    Folder.GetFiles Folder: $'''C:\\Users\\ohost\\OneDrive\\Desktop\\Test Folder''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP LoopIndex FROM 0 TO Files.Count - 1 STEP 1
     File.RenameFiles.RenameAddText Files: Files[LoopIndex] TextToAdd: ExcelData[LoopIndex]['Account Name'] TextPosition: File.AddTextPosition.BeforeName IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
    END
    

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • ohostetler1 Profile Picture
    21 on at

    Agnius,

     

    Thank you for your response I am still getting a loop error I was hoping you could tell me what I'm doing wrong. As far as your consultant offer I may be calling you in the next few months I believe there is going to be a need for some PA for a project that I will be starting that will more than likely be out of my league (knowledge level).  Thanks again (screenshot of the error below).  

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @ohostetler1 

     

    Looking at the error, it seems to be an issue with %Files.Count% , could you check what type is %Files%, is it the collection and also check its value in flow variables panel to confirm 🙂

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Have you copied the code I provided into your designer, or did you try to create the actions yourself by looking at the screenshots I have provided?

    The "End to" value in the Loop action should be %Files.Count-1%. It seems like you typed in %Files%.Count-1. This is not the correct syntax.

     

    P.S. The below is just my signature. I have it on all of my answers as a means to remind the author to give me a thumbs up or mark my answer as a solution if I actually solve their problem. Some people forget it if they're not reminded 😊 It's not aimed specifically at you, but if you are interested in some consultancy/development services, feel free to drop me a message.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

     

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 227 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 221 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 132

Last 30 days Overall leaderboard