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 / Renaming of files base...
Power Automate
Answered

Renaming of files based on original file name

(1) ShareShare
ReportReport
Posted on by 263
I have over 1200 files that have a staff number which is an 8 digit number beginning with 1 and which can be at various points within the naming convention of the file.  
 
For example 12345678 John Doe.pdf or John 12345678 Doe.Pdf or John Doe 12345678 ABC.pdf.
 
I want to build a flow that will take the meta data of the file name and reconfigure the name so that the staff number is always first no matter where it appears in the original file's naming convention.
 
The flow will be as follows however I am not sure what the compose expression should be to handle the variable file name and also the variable file extension.   Any assistance would be greatly appreciated.
 
 
 
I have used the following expression and it works but only when the staff number follows the first name and surname in the file naming convention 
 
concat(
    last(split(split(triggerOutputs()?['body/{FilenameWithExtension}'], '.')[0], ' ')),
    ' ',
    first(split(split(triggerOutputs()?['body/{FilenameWithExtension}'], '.')[0], ' ')),
    ' ',
    skip(split(split(triggerOutputs()?['body/{FilenameWithExtension}'], '.')[0], ' '), 1)[0],
    '.',
    last(split(triggerOutputs()?['body/{FilenameWithExtension}'], '.'))
)
 
 
 
Thank you in advance for any guidance / help you can provide.
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
    Hi,
     
    Here is a way. I was actually just curious if this would work. There are plenty of ways.
     
    In My Example I tested all 3 of the example names you wanted. and they always produced the correct name for what you wanted and the alph in the
    correct order AFTER the Number.
     
    in this run I had
    John 12345678 Doe.pdf
     
    And ended with
    12345678 John Doe.pdf
     
    Steps 
    1. I create a manually triggered flow
    2. I created a variable that I could change the name of (so I could test all the orders you had above). I could have simply used an Array and looped.. But I was lazy
     
    3.. Split the string by . (period), and take the index [1] so that I can get the Extension
    split(variables('Name'),'.')[1]
     
    4. Create an Array of the Name Parts. Doesn't matter if there is only 1 though.
    I split the name by Period again, but then I split the output of the (the 0 index) by a space. Since the [0] index no longer as the
    . or the extension we just get the Number and the Alpha
     
    split(split(variables('Name'),'.')[0], ' ')
     
    5. Use a Select, and the IsInt expression to grab JUST the number
    IsInt(item())
     
    6. Copy Step 5 and Paste it back in, but this time, change the expression to not, as we just want the alpha parts
    not(IsInt(item()))
     
    7. Union the two arrays together (merge them), making sure the left side is the Number part
    union(body('Get_the_Number_Part'),body('Get_the_Alpha_Parts'))
     
    8. Now turn it back into a string (aka file name)
    So what we want to do
     
     
    Is to concat the JOIN of the union output. The union output will be an array with the number first and the alpha parts next.
    , then we need to add the . (period) and the extension, so it looks like this.
     
    concat(join(outputs('Union_the_two_Parts_with_the_Number_output_first_always'),' '), '.', outputs('Get_Extension'))
     
    And we have our correct name (per the RUN above all this).
     
     
     
     

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 791

#2
Valantis Profile Picture

Valantis 582

#3
Haque Profile Picture

Haque 529

Last 30 days Overall leaderboard