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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / OCR rename multiple im...
Power Automate
Unanswered

OCR rename multiple image files

(0) ShareShare
ReportReport
Posted on by 141

Hi, 

 

I'm looking for suggestions on how to make this flow variable and OCR scan more than 1 specific file. I've tried changing the 'files' in the text detection but it brings up an error. Also the text detection response variable changes between 1-Xnumber for where the Job number is detected in each image. The number is always only 5 Numbers. Would colour coding be a good strategy to always extract the right information I need? Any ideas? I've attached an image of the flow of got working currently. 

Simple image ocr rename.jpg

I have the same question (0)
  • momlo Profile Picture
    1,527 Super User 2024 Season 1 on at

    Hi @jkingno1 

    Get files action gets you list of files, now you need to iterate it with "For each Loop".

    Then, each iteration willl execute code in the loop will be executed against 1 file from the list stored in a %CurrentItem% variable.

    In your example, text detection and rename actions need to be moved inside the loop

    Text detection needs to reference the name of the %CurrentItem%

    In rename action you get the filenaem from JSON, so if this value is constant you will have namign conflict so you need to make it dynamic (filename or path).


    You can learn loops here, also there are quite a few threads on this forum talking about this particular topic - renaming files in loop so take a look at those too.

    https://learn.microsoft.com/en-us/power-automate/desktop-flows/use-loops#for-each-loop

  • jkingno1 Profile Picture
    141 on at

    Hi @momlo

    Thanks for your response. So far I have implemented a loop that works to an extent, the only problem I get is that the text detection sometimes detects multiple 5 numbers and chooses the highest number which is not correct. If I add a "JN:" next to the Job number e.g. "JN:34738" how would I get a regex to detect for that?

    I also need a way to append the data with a (1),(2),(3) etc and I'm not sure how to do that. I tried append text but I believe it isn't the correct option. Any ideas? I've attached an image of my flow. Thanks heaps!

    Screenshot 2023-01-20 093643.jpg

  • momlo Profile Picture
    1,527 Super User 2024 Season 1 on at

    Hi @jkingno1 

    You can use lookaheads to match digits only where there is specific content before or after digits:

     

    Match 1 or more digits after "JN:"

    (?<=JN:)\d+

     

    Match 1 or more digits between "JN:" and "text after number"

     

    (?<=JN:)\d+(?=text after number)

     

     

  • Verified answer
    jkingno1 Profile Picture
    141 on at

    Thanks for your help @momlo 

    I've implemented a JN\d{5} regular expression which works really well, I realized the : cant be used when renaming the file, and I also worked out myself how to create a parenthesis (If that's what its called when a (1),(2) (3) is added at the end of the 'same name', which was done by generating a random number at the end. Here's the flow I got for anyone in future who has the same problem. 

    Screenshot 2023-01-20 154351.jpg

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    I don't know Jason, so I'm just going to reiterate what I think you are trying to do, and give you an answer for that assumption.

     

    Do you just need the last 5?  If so, you don't need a regex.

     

    For each %CurrentItem% in files

        Get subtext from %CurrentItem.NameWithoutExtension% starting from %CurrentItem.NameWithoutExtension.Length - 5% to end of text 

     

    Then for Rename Files, looking at your loop, the If statement (steps 8-11) would rename the %CurrentItem% and then following that step 12 would try to rename the item again, but if %CurrentItem% has already been renamed, then you aren't going to find %CurrentItem% where it used to be, so step 12 will always error out if the if statement is true.

     

    If you are trying to use one rename or the other, you want to use IF -> Else.  It goes like this:

     

    If (calculation is true)

        'do something

    Else (if not true)

        'do the other thing

    End (if)

     

    Also, %Match% is just 5 digits, correct?  If so, you can't use Match for the If file exists parameter.  It needs to be a whole file path:  something like %FromPath%\%Match%.jpg

     

    Hope this all helps.

        

  • jkingno1 Profile Picture
    141 on at

    Thanks for your reply, i appreciate the help. Luckily i just figured it out which you will see as the marked solution. 🙂

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard