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 / Automatically Rename N...
Power Automate
Answered

Automatically Rename New Files on Upload with a Sequential Suffix

(0) ShareShare
ReportReport
Posted on by 57

I have a Document Library with subfolders for storing photos. There will be lots of photos, with more added all the time.

 

I would like to have the photos automatically renamed to "SubFolder_X", where SubFolder is the subfolder in which the file is stored and X is a number that increases sequentially as photos are added (SubFolder_1, SubFolder_2, SubFolder_3, and so on). Simple enough. 

 

But I cannot seem to figure out how to do it.

 

Any ideas?

 

 

Categories:
I have the same question (0)
  • notj Profile Picture
    782 on at

    Can you not use the ID of the file? That's already a sequential number that's generated for you. So you would just need to do an update file properties action.

  • HMP Profile Picture
    57 on at

    I think that will be my fallback. I have at least a dozen subfolders, and each is going to receive hundreds of photos, so that ID number is going to get long and fast. So I was hoping to start at 1 in each subfolder.

     

    I did find this, and it works for renaming files as they are uploaded. I can even include things like who uploaded the file in the name, and the file ID. I set it up to handle the whole library, but still can't sort out how to get the SubFolder name involved. It would be nice if I didn't have to make a flow for each and every subfolder. 

  • notj Profile Picture
    782 on at

    Alternatively, if I was going to tackle this and didn't want to use ID, I would store the number in a separate column for easier access. You don't have to show the column in the view of the library.

    Make a view in the library that sorts the files highest to lowest based off this new columns.

    Do a get files action, targeting that specific view, return 1 item only.

    Do a compose action with that number from the column, +1.

    In my update file properties action, use this compose action results and put it into the column used for tracking the numbers.

     

    I could see a potential where 2 separate flow runs come up with the same number if you have multiple runs going at the same time.

  • Verified answer
    HMP Profile Picture
    57 on at

    I think I'll go the route of creating a hidden column that starts at 1 and goes up from there. For now, here is what I did to get the files to rename on upload, to SubFolder_ID:

     

    RenameFileAutomatically.png

     

    Split File Path

    Expressionsplit(triggerBody()?['{Path}'],'/')

     

    Get SubFolder Name

    Expressionlast(take(outputs('Split_File_Path'),sub(length(outputs('Split_File_Path')),1)))

     

    Send an HTTP request to Sharepoint to get type

    Uri: _api/lists/getbytitle('Photos')

     

    Send an HTTP request to SharePoint to rename file

    URI: _api/lists/GetByTitle('Photos')/Items(@{outputs('Get_file_properties')?['body/ID']})

    Headers:

    • Content-type: application/json;odata=verbose
    • IF-MATCH: *
    • X-HTTP-METHOD: PATCH

    Body

    {'__metadata':
    {'type':'@{outputs('Send_an_HTTP_request_to_SharePoint_to_get_type')?['body']?['d']?['ListItemEntityTypeFullName']}'},
    'FileLeafRef':'@{outputs('Get_SubFolder_Name')}_@{outputs('Get_file_properties')?['body/ID']}'}

     

    NOTE: If you copy+paste what I did, make sure you rename the various Actions as I have done

     

    Credit where credit is due: I got the SubFolder stuff from here, and the HTTP stuff from here.

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!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 250 Super User 2026 Season 1

#2
Expiscornovus Profile Picture

Expiscornovus 222 Most Valuable Professional

#3
Haque Profile Picture

Haque 174

Last 30 days Overall leaderboard