Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Using substring and indexOf to get middle of string between two indexes, but having trouble

(0) ShareShare
ReportReport
Posted on by 4

I've got a flow set up to send a bot message to Teams when a file is changed in a shared OneDrive directory. The message includes a link to the folder where the file resides. I want the text of this link to be the path of the directory, but in order for it to be user friendly, I want to only keep the part of the path which is after 'root:' and before the file name.

I want to do something like this:

substring( File Path, indexOf( File Path, 'root:' ) + 5, indexOf( File Path, File Name ) - indexOf( File Path, 'root:' ) + 5 )

 

To take this: 

"/drives/b!KosGUJrQ10-JHf8xWUb2Zvba5vzW4a2Du7qcWPXQ99r1usopxzphRrN1IXAVuIeF/root:/External Shared/10466_SAFB/Exports/SAFB_PP.nwc"

to this: 

"/External Shared/10466_SAFB/Exports/"

 

From what I can tell, Power Fx doesn't like the math operators in my expression. The expression returns no errors without the operators, but without the operators, I can't get the specific mid section of the string I want.

 

Any work arounds or suggestions?

  • j_f Profile Picture
    4 on at
    Re: Using substring and indexOf to get middle of string between two indexes, but having trouble

    Thanks! I'm happy there are people out there who know more than me! I got the result I wanted using a combination of add() and sub() within the substring() function and Dynamic input for the path.

     

  • grantjenkins Profile Picture
    11,059 Super User 2025 Season 1 on at
    Re: Using substring and indexOf to get middle of string between two indexes, but having trouble

    Hopefully this will get what you're looking for. Assuming the Path is in a Compose action.

     

    slice(outputs('Compose'), add(indexOf(outputs('Compose'), 'root:'), 5), add(lastIndexOf(outputs('Compose'), '/'), 1))

     

    grantjenkins_0-1681309409335.png

     

    grantjenkins_1-1681309450640.png

  • Verified answer
    Expiscornovus Profile Picture
    31,732 Most Valuable Professional on at
    Re: Using substring and indexOf to get middle of string between two indexes, but having trouble

    Hi @j_f,

     

    If you want to add 5 characters you could use the add function instead of the +

     

    Try something like:

    add(indexOf( File Path, 'root:' ), 5)

     

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May 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 >