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 / Help With Expression T...
Power Automate
Answered

Help With Expression To Create A Folder in ODFB

(0) ShareShare
ReportReport
Posted on by 7

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?

Categories:
I have the same question (0)
  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    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

  • m0p0h0 Profile Picture
    7 on at

    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?

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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

  • m0p0h0 Profile Picture
    7 on at

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

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
David_MA Profile Picture

David_MA 250 Super User 2026 Season 1

#2
Expiscornovus Profile Picture

Expiscornovus 222 Most Valuable Professional

#3
Haque Profile Picture

Haque 174

Last 30 days Overall leaderboard