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 Files Inside ...
Power Automate
Unanswered

Renaming Files Inside a Folder with Substring of Folder's Name

(0) ShareShare
ReportReport
Posted on by

Hi all!

 

I'm looking to make a Microsoft Flow that can rename files inside a folder to a substring of name of said folder.

 

My current folder structure is set as follows:

 

/Main Folder/Subfolder 1/File to Be Renamed 1

/Main Folder/Subfolder 1/File to Be Renamed 2

/Main Folder/Subfolder 1/File to Be Renamed 3

/Main Folder/Subfolder 2/File to Be Renamed 1

/Main Folder/Subfolder 2/File to Be Renamed 2

/Main Folder/Subfolder 2/File to Be Renamed 3

...

 

So in essence, the main folder has multiple subfolders inside it, and within each subfolder itself there are also multiple files that need to be renamed.

 

My Flow can currently access each embedded subfolder and its respective items, but I am currently having trouble with renaming each individual file.

 

The naming format for the subfolders are a name and an ID denoted by brackets e.g. Michael (123456), and I want the ID from the subfolder's name to be appended to the files inside. This means that some form of manipulation of the name string is required to remove all characters before and including the open bracket "(", as well as the close bracket ")" at the end.

 

In summary, if my subfolder name is Michael (123456), I want the files to be named 123456 File 1, 123456 File 2, 123456 File 3 and so on and so forth.

 

Here's what I have currently:

2023_05_31_11_38_19_Edit_your_flow_Power_Automate.png

2023_05_31_11_39_46_.png

 

The Compose action was just me playing around and trying to a solution. Right now, here's the expression inside the Compose action:

 

 

 

split(split(outputs('Move or rename a file')?['body/name'],')')[0],'(')[2]

 

 

 

which doesn't seem to work due to the data type that I get from outputs('Move or rename a file') (or maybe I'm wrong about why I'm wrong).

 

Any help would be great! Thanks!

Categories:
I have the same question (0)
  • Manish Solanki Profile Picture
    15,109 Moderator on at

    Hi @elegantpeacock 

     

    You need to make couple of changes to make it work.

    Firstly, drag 'Compose' action at the start of 'Apply to each' action to get the name of the folder:

    ManishSolanki_0-1685509086010.png

    Expression used here to get the ID from folder name is:

    first(split(last(split(item()?['name'],'(')),')'))

     

    Next, we need to update the Destination file name to rename the file. It consists of the folder path from filter array, ID from compose output followed by blank space and Name of the file from current iteration:

    ManishSolanki_1-1685509265264.png

    Expression used here is, just copy & paste the below expression in your flow:

    @{items('Apply_to_each')?['Path']}/@{outputs('Compose')} @{items('Apply_to_each_3')?['Name']}

     If it gives error, then modify the expression as per the variables or action name (Apply to each, Compose etc.) used in the flow.

     

    If this helps, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    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!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 58

#2
David_MA Profile Picture

David_MA 53 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 36 Most Valuable Professional

Last 30 days Overall leaderboard