cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

File path without filename and extension?

Hi everyone,


I am new to Microsoft Flow, and by no means a coder, so sorry for my lack of knowledge.

 

I am creating a flow to one-way sync content from a given location on my OneDrive for Business to a given location at my personal OneDrive, including all subfolders. I almost got it working by creating this creating a Flow now.

 

I made this to grab my input from OneDrive for Business:

-When a file is modified and created in my chosen folder (Including subfolders)

-Get file contents for the file

 

Then use "Create file" in OneDrive, but here's where I am having trouble with a field. Filename and file content works by taking the dynamic content from the input. However "Folder Path" is my problem. If I use the file path dynamic content it creates a folder with the file name in the location the file is supossed to be, and puts the file into that. So I get:

/Sample Folder/Sample File.txt/Sample File.txt

 

Instead of:

/Sample Folder/Sample File.txt

 

So how can I pull the file path without filename and extension, or in other ways manipulate the dynamic content path?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: File path without filename and extension?

Hi @pandaym,

 

You could try this method now, I changed the formula according to your trigger and see if this helps you:

replace(triggerBody()?['Path'],last(split(triggerBody()?['Path'],'/')),'')

16.PNG

Please take a try.

 

Best Regards,

Barry

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

7 REPLIES 7
Highlighted
Helper I
Helper I

Re: File path without filename and extension?

Hi @pandaym,

 

Please see the configuration for your Flow below.

Make sure you have the /Sample Folder created in the Root of your Personal OneDrive.

Flow.jpg

Best regards,

Ovi.

Highlighted
Community Support
Community Support

Re: File path without filename and extension?

Hi @pandaym,

 

Your most fundamental requirement should be to get the file path of the corresponding file and populate it in Folder Path field of the OneDrive for personal-Create file.

You could refer to this method:

I didn't find a Trigger like When a file is modified and created, using When a file is created(Preview) as the trigger, and then I can create the file directly using the output of the trigger.

Configure OneDrive for personal-Create file action, fill in the corresponding formula in the corresponding field, note that the formula needs to be written in Expression first, and then filled in the field.

Image reference:

65.PNG

Use this formula to get the folder path of the file:

replace(triggerOutputs()['headers']['x-ms-file-path'],last(split(triggerOutputs()['headers']['x-ms-file-path'],'/')),'')

This formula gets the file name:

triggerOutputs()['headers']['x-ms-file-name']

Please take a try and feel free let me know if you have any issue.

 

Best Regards,

Barry

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.
Highlighted
Frequent Visitor

Re: File path without filename and extension?

Thank you for your answers.

I've tried, but unfortunately, I cannot get it working. I have unfortunately never worked with expressions before, and have no coding experience at all. So I tried just copying your expression directly to the flow.

 

I have added pictures of my flow, and the error that I get. Please note that the first trigger is "When a file is created or changed (Properties only). The next one is "Get filecontent". For some reason it picks them up in my local language here. 

 

Can you help me troubleshoot?

Highlighted
Community Support
Community Support

Re: File path without filename and extension?

Hi @pandaym,

 

Could you please temporarily set the language of your Flow portal to English?

Sorry, I don't understand what triggers and actions you have configured.

 

Best Regards,

Barry

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.
Highlighted
Frequent Visitor

Re: File path without filename and extension?

My interface is in English, so I don't know why sometimes the triggers and actions translate when I add them. I think it is something that is messed up in my organizations locale settings. I could rename the actions, but the rename is now disabled, after I added more things.

But the first trigger is "When a file is created or changed (Properties only). The next one is "Get filecontent". 

 

sync3.jpg

 

 

Highlighted
Community Support
Community Support

Re: File path without filename and extension?

Hi @pandaym,

 

You could try this method now, I changed the formula according to your trigger and see if this helps you:

replace(triggerBody()?['Path'],last(split(triggerBody()?['Path'],'/')),'')

16.PNG

Please take a try.

 

Best Regards,

Barry

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

Highlighted
Frequent Visitor

Re: File path without filename and extension?

Beautiful! It works perfectly now! You are a legend, thank you so much for spending time helping me.

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

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!

Top Solution Authors
Top Kudoed Authors
Users online (8,327)