cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
m0p0h0
New Member

Help With Expression To Create A Folder in ODFB

I almost have this working but I am stuck on getting the folder created.

 

I am keeping two ODFB (OneDrive for Business) location in sync.  I have one Trigger and One Action in the Power Automate Flow.

1. (Trigger) When a file is Created in Source

2. (Action) Create a file in Destination

 

The action requires 3 properties to work (a) Folder Path (b) File name (c) File content.  (b) and (c) I can get from the Trigger.

For (a) the Folder Path I need to create the folder path if it does not exist.  This works if I supply a folder name that doesn't exist then it will create it.  I am using an expression as follows to create the folder:

 

last(split(base64ToString(triggerOutputs()?['headers']['x-ms-file-path-encoded']),'root:/'))

 

This creates a folder but the folder it creates is the name of the file rather than just the folder path.  For example, if the name of the file it is supposed to create is "somefile.txt" in "FolderX".  Then it will create a folder as follows in the ROOT (/) -> /folder1/folder2/somefile.txt/somefile.txt

 

The file is created but it is created inside a folder.

How can I use my expression in the File path property to create /folder1/folder2/somefile.txt folder path instead?

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Super User
Super User

Hi @m0p0h0 
 
Based on your first expression contained with a compose action, you could run the following:
 
substring(outputs('Compose'),0,lastIndexOf(outputs('Compose'),'/'))
 
Get the last index of / and get the substring from 0 to that position.
 

Please consider accepting my answer as a solution if it helps to solve your problem.

Cheers
Damien

Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

View solution in original post

4 REPLIES 4
DamoBird365
Super User
Super User

Hi @m0p0h0 
 
Based on your first expression contained with a compose action, you could run the following:
 
substring(outputs('Compose'),0,lastIndexOf(outputs('Compose'),'/'))
 
Get the last index of / and get the substring from 0 to that position.
 

Please consider accepting my answer as a solution if it helps to solve your problem.

Cheers
Damien

Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

Thanks very much for replying.  Just to try clarify - do you mean to replace my expression completely with the suggested expression?

Or to run your suggested expression after on the outputs from mine?

Hi @m0p0h0 

 

Run the expression on top of your existing. I’ve assumed it’s in a compose action. 

You could alternatively replace both outputs(‘compose’) with your expression.

 

Damien

This worked like a champ. Thanks for taking the time.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (2,687)