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 Automate
Suggested Answer

Numbering files

(1) ShareShare
ReportReport
Posted on by 60
I'm stumped and it shouldn't be this hard.
 
I have a flow that I'm using to convert all attached files in a new Sharepoint list item to JPEGs and want to rename them all to the same name with a number at the end (1),(2),(3)...
The Flow is in french so here's the jist of it. When an item is created, I get the attached files and then loop for each convert the file to PDF then convert the PDF to an image list. Then I used the Add attachment to save the attachement with the new name that I want. Obviously, it won't work with multiple attachments since it can't save the same name twice.
Therefore, I added an Initialize variable and then an increment variable to count the For each 1, and add that number in the filename. This works, but if the image list from one of the attachments has more than one image, it doesn't work because again, I'm save the same name with the same integer. I tried to add a second initialize variable and increment variable for the second For each, but it doesn't let me add an initialize variable inside a loop.
 
For example. My item has 2 attachements. An excel file that converts to 3 images and a photo.
 
I get the first excel image file as : image(1).jpg and the photo as image(2).jpg. but the 2 other images from the excel don't work because they also will be called image(1).jpg
 
 
How can I do this. I would like to have something like : image1(1).jpg, image1(2).jpg, image1(3).jpg and image2(1).jpg
 
 
 
 
EDIT:
I almost got it.
 
I added a second initialize variable before the first loop and a increment variable inside the second loop. It kind of works.
What I get now is : image1(1).jpg, image1(2).jpg, image1(3).jpg and image2(4).jpg
 
It does the job, but I would rather it restarted numbering with subsequent files (image2(1).jpg).
Any ideas?
Categories:
I have the same question (0)
  • JDucharme Profile Picture
    60 on at
    I almost got it!
     
    I added a second «Initialize variable» right after the first one. And then added an increment variable in the second For each loop. It kind of works...
     
    But I get this : image1(1).jpg, image1(2).jpg, image1(3).jpg and image2(4).jpg.
     
    It will do the job, But is there a way to start over at 1 for the subsequent files?
  • Pstork1 Profile Picture
    69,347 Most Valuable Professional on at
    Have you considered incorporating the name of the Excel file or the Photo into the finished name? Then the numbers wouldn't conflict because it would still be a unique filename. That would be easier than trying to increment a name through multiple loops.
  • JDucharme Profile Picture
    60 on at
    Thanks for your suggestion, but it's for the finance department. They need the image to be called a specific string of names (supplier_invoiceNo_invoiceDate) and then the incremental number. Incorporating the original name would just be unwanted visual junk.
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,976 Moderator on at
    Hi
     
    Let me start by educating something. You should never use Variables that were creating outside of a Loop, Inside. This is because the loops are not thread safe and therefore ALWAYS have the ability to be impacted and will name stuff incorrectly. 
     
    Imagine that two were going at the same time. They both increment BEFORE they save... well now you have 2 named the same anyway.
     
    What you want to do is, On the For Each, look at the properties (go to the old Ui its faster). Click on settings then turn on Concurrence and set it to 1
     
    This way, while it does make it run serially it will guarantee that your names will never have the same number more than 1 time or worry about issues of Concurrency that you WILL have right now
     
    What I do not understand is why you need multiple loops. Is it because a file can have other stuff in it so you need to pull it out. I didnt follow tha tpart.
     
    If you have 4 things to save, why do you need more than 1 Integer, again I dont understand.
     
    Your walkthrough says you get 1-N attachments, where did the Sub for each come from and why?
     
    Based on what you described you should only have to loop through the attachments
    Incrementing the Variable (making usre Concurrence is set to 1) each loop
     
    And done.
     
     
  • JDucharme Profile Picture
    60 on at
    Thanks for the info. I didn't know that. I wasn't able to put the initiate variable inside the loops. Having said that, each entry will have different names because they come from a SharePoint list and the invoice numbers will always be different. I'm saving them back in the same SharePoint list item so event if there were two of the exact same, it wouldn't matter since they are going to different places.
     
    The multiple loops are there because there might be 2 or more attached files, so the first loop is to separate them, and the second loop is because the PDFs are converted into an array of images. I need to rename these images to the same name with an incrementing number. 
     
    I found how to set the concurrence to 1 but I don't see how this is useful for me to number my files. How do I get the iteration number for each cycle and add it to the name?
     
    Thanks 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 569

#2
Valantis Profile Picture

Valantis 484

#3
Vish WR Profile Picture

Vish WR 460

Last 30 days Overall leaderboard