cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous5 Helper II
Helper II

Using Split Function for Folder Path

Hi Everyone,

 

I'm working on a flow which is successfully working but I'd like to add a parallel branch to work on the same initial trigger of File Creation in Sharepoint (properties only).

 

I've made this branch get the file content and attach it to an email in Outlook which is working. What I would like to do is personalize the email using info from the filepath. For example, the complete file with the folderpath would look something like:

 

Job Site Name/Service Reports/Vendor Name/PO 12345 Service Report.pdf

 

What I'd like to do is have Flow compose an email and enter the subject with dynamic content dictated by the "Vendor Name" above from the file path. Also, I'd like to use the filename (without extenstion) as an output for use later in the flow This would look something like:

 

Subject: (filename) from (Vendor Name)

Body: Please see the attached (filename) from recent attendance by (Vendor Name). Thank you.

 

I assume that extracting this information would use some combination of the compose function with last and split expressions. I've tried many combinations but I cannot get it to execute properly. I also tried to "Set Variable" but that cannot be done at the branch level of the flow.

 

Can anyone assist in this effort?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Using Split Function for Folder Path

 

Hi @Anonymous5 ,

 

Please refer to the following methods to get the data you need.

Note that the Folder Path of the trigger output does not contain filename.

Expression reference:

split(triggerBody()?['{Path}'],'/')
last(take(outputs('Compose'),sub(length(outputs('Compose')),1)))

Image reference:

21.PNG

Hope it helps.

 

Best Regards,

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

View solution in original post

6 REPLIES 6
Highlighted
Super User
Super User

Re: Using Split Function for Folder Path

@Anonymous5 

Please see my screen shot below.

The output of the Get Vendor Compose action will give you the vendor.

The output of the Get Filename Without Extension will give you the file name.

I could have combined the first two actions into a single action with the following expression: split(body('Get_file_properties')?['{Path}'],'/')[3]

ParsePath.jpg

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Anonymous5 Helper II
Helper II

Re: Using Split Function for Folder Path

Hi Scott,

 

Thanks very much for the guidance. I have been incorporating your suggestions and I feel I am very close to what I need. Since I am already getting the file properties at the initial trigger I am using the following to split out the folder path:

 

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

 

This is working and produces an output of each portion of the filepath listed in order as the output. Using the second "compose" expression to grab the 5th (in my case) item did not work. Trying to combine the bracketed number at the end is NOT working and creates a blank input and output. 

 

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

 

Ideally, I'd like to use the "last" feature to go after the final folder name. I've tried a few combinations of last(split(...)) but still no luck. On top of that, the split feature that is working produces a list of folder names all surrounded by quotes with the last one being "". My fear is that if the "last" feature works it will just produce an empty output.

 

I know this is long-winded but I'm hopeful that I'm very close to getting it figured out with a little more help. 

Community Support
Community Support

Re: Using Split Function for Folder Path

 

Hi @Anonymous5 ,

 

Please refer to the following methods to get the data you need.

Note that the Folder Path of the trigger output does not contain filename.

Expression reference:

split(triggerBody()?['{Path}'],'/')
last(take(outputs('Compose'),sub(length(outputs('Compose')),1)))

Image reference:

21.PNG

Hope it helps.

 

Best Regards,

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

View solution in original post

Super User
Super User

Re: Using Split Function for Folder Path

@Anonymous5 

The folder path from my post above looks like this:

ParsePath/MyJobSite/Service Reports/My Vendor/

 

The output of my split expression from my post looks like this:

[
"ParsePath",
"MyJobSite",
"Service Reports",
"My Vendor",
""
]

 

As you can see, the vendor folder, although it is the last folder in the path is not the last item listed.  As a result, the last() expression will not work.

Also, the elements in the array are zero based - the first element is element zero.  Therefore, I need to refer to element 3 to get the vendor folder:  split(body('Get_file_properties')?['{Path}'],'/')[3]

 

If the folder depth will vary, you'll want to use the solution provided by @v-bacao-msft 

 

 

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Anonymous5 Helper II
Helper II

Re: Using Split Function for Folder Path

Hi Scott,

This is great information thank you. I’m always learning working with Flow. It seems like another way to accomplish the same goal. I suppose this could also be considered a solution.
Anonymous5 Helper II
Helper II

Re: Using Split Function for Folder Path

Hi Barry,

Thank you! This has solved my issue.

Rgds,
Rob

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (7,872)