Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Get substring from file name and move to matching SharePoint Online folder

(0) ShareShare
ReportReport
Posted on by 68

Hi,

I'm having difficulties trying to achieve the following scenario using Power Automate - I have a document library holding many folders. Each folder is named after an individual employee and her/his ID number, for instance John Doe, 1111111, the ID will always come after a comma, or some other separator. There is another document library, to which files for these employees will be uploaded. The file names will contain the name and the ID of the employee. Now what I'm trying to achieve and create an automation for is, to get the ID number out of the name of the file as it'll always be unique, out of the whole string, then look for the folder in the first document library holding all user folders containing this substring and based on that, to move it to that folder that matches the ID substring. Any help/ideas will be very much appreciated.

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    @v-litu-msft  - Hi, hope you are doing well? If I could ask you again for an advice and possible resolution to my task. You helped me a lot so far, but now I'm struggling for days to achieve the following - Once a file is created in a SharePoint folder, for the demo purposes let's name it Library1, I need to extract the file's ID from the name string of the file, which will be something like this - JohnDoe-JD-012345-DF-CONF.docx, so I need just the 0123456 part. Then I need to find the folder within that main folder Library one that contains that ID, something like folder JohnDoe_0123456 and place that file there. That you helped me with and I think is working fine now. The new part is, if the ID of the document is not included in any folder (that means that there's no such user in the folder), the folder to be created in the main Library1 and the file placed inside. Also each of these user folders within the main Library1 folder will have to subfolders inside called "Confidential" and "General". So what I have to also achieve is not only to place the document to its corresponding folder that contains its ID, but if the document also contains CONF in its name, to place it inside the Confidential folder, if not, in the General? Have been trying for days with no result whatsoever. Any help would be very much appreciated, thank you in advance!

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    @v-litu-msft -Thank you, works perfect and depending on the digit inside of the brackets, I can manipulate what to return, after which - sign.

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Thank you as usual! Will try it and let you know.

  • v-litu-msft Profile Picture
    on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Hi @benny_blanco,

     

    Use the split() function could do it:

    split function could separate a string by a substring, convert it into an array, then index could extract member of the array:

    split(outputs('Compose'),'-')[2]

    Annotation 2020-06-05 153814.jpg

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    @v-litu-msft  - Can I ask you for some help again as I can't figure it out. It turns out the actual string looks like this -

     

    JonasSmith-Joe-1234567-CLMPDVVD-TB.pdf

     

    and I need to extract only the ID part, only the digits you see and then look for that ID in the folders, if they contain it. How can I extract the ID alone first, then the name at the beginning alone again? Thank you for the support!  

  • v-litu-msft Profile Picture
    on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Hi @benny_blanco,

     

    Use the split() function again, separate by ".", for example:

    first(split('1111.excel','.'))

    It will return: 1111

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Hi @v-litu-msft ,

     

    Thank you, it worked! 

     

    Something else I want to ask though about the formula you provided - it gets everything after the separator, but gets the file extension as well (.pdf, .docx). How can I make it work without getting that part, the file extension?

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Thank you for that! Let me test and will let you know.

     

    Cheers!

  • Verified answer
    v-litu-msft Profile Picture
    on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Hi @benny_blanco,

     

    Yes, after you get the ID, please refer to the following steps:

    Annotation 2020-05-08 172205.png

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • benny_blanco Profile Picture
    68 on at
    Re: Get substring from file name and move to matching SharePoint Online folder

    Thank you for the formula! Replaced the name and ID part with the dynamic value of the actual document name and it is separating and returning everything after the separator. Any ideas on how to make it look for the one folder that contains the same ID information and to move it there automatically?

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1