web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get the folder in Shar...
Power Automate
Unanswered

Get the folder in Sharepoint where file is

(0) ShareShare
ReportReport
Posted on by 7

Hello

 

I am very new to these flows and wanted to ask how you set up flows to get the folder name where files are located

 

E.g. file would be 

SharepointLibrary/FolderA/ExcelFile.xls

 

variable would get value FolderA

 

br Jouni

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    Hello @Joumar12 

     

    What would be the trigger for the flow to run? i.e. would you want a weekly email listing all files in your document library along with what folders each document is in?

     

    Thanks

     

    Bradley

  • Joumar12 Profile Picture
    7 on at

    Hello

     

    In the end I am looking a way to add the folder name as metadata to the file each time a new file is added to the library. However first I need to run manually triggered flow for those files already in the library to add the Folder name as metadata to the existing files

     

    Any help appreciated... thanks!

     

    Br Jouni  

  • Verified answer
    fchopo Profile Picture
    8,003 Moderator on at

    Hello @Joumar12 

    You could use an expression like this:

     

    Replace(Replace(your_element?['folder'],'SharepointLibrary/',''),'/','')

     
    Wheree your_element will depend on the action you are using. 
    Hope it helps!
    Ferran
  • Joumar12 Profile Picture
    7 on at

    Wow! it was that simple... and I tried all kind of changing to array etc....

     

    Many Thanks!

  • Nicolas_P Profile Picture
    19 on at

    Hello @fchopo !

    "Where your_element will depend on the action you are using." - that means i need to using the

    Replace(Replace(triggerBody?['folder'],'SharepointLibrary/',''),'/','') to return the folder name or something else? 

     

    Regards, N.

  • fchopo Profile Picture
    8,003 Moderator on at

    "Where your_element will depend on the action you are using" means it depends on your trigger or action where the value to be replaced is.

     

    Which trigger or action are you using before calling this expression?

  • Nicolas_P Profile Picture
    19 on at

    I'm using the https://prnt.sc/r52epo method, it add the filename in letter draft.  So, next line i would like to add the folder name, where is this file contain. 

  • fchopo Profile Picture
    8,003 Moderator on at

    I'm not sure I understand what you need... Do you need a string with the folder and the filename? If that's the case, you could do something like this:

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

    Hope it helps!

    Ferran

  • Nicolas_P Profile Picture
    19 on at

    Dear Ferran! 

     

    It's absolutely help, and the full path was return to email body, but...) 

    I need only the highest folder, where file contains, not all the path, for example: 

    Shared Documents/Main/10#Guide//Services_test.pdf

    in my case i need only to return 10#Guide (folder name), and preferable without first two digits and symbol#, it using to sort files.

    Is it's possible?
    Regards, Nicolas.

  • fchopo Profile Picture
    8,003 Moderator on at

    Why don't try something like this:

     

    - Find where is the '#' character: indexOf(triggerBody()?['{FileNameWithExtension}'],'#')

    - Find where is the last index of '/': lastIndexOf(triggerBody()?['{FileNameWithExtension}'],'/')

    - Find how many characters are between them (sub function): sub(lastIndexOf(triggerBody()?['{FileNameWithExtension}'],'/'),indexOf(triggerBody()?['{FileNameWithExtension}'],'#'))

    - Length of the folder (without #): 

    sub(sub(lastIndexOf(triggerBody()?['{FileNameWithExtension}'],'/'),indexOf(triggerBody()?['{FileNameWithExtension}'],'#')),1)

    - Get Folder Name:

    substring(triggerBody()?['{FileNameWithExtension}'],add(indexOf(triggerBody()?['{FileNameWithExtension}'],'#'),1),sub(sub(lastIndexOf(triggerBody()?['{FileNameWithExtension}'],'/'),indexOf(triggerBody()?['{FileNameWithExtension}'],'#')),1))

    Hope it helps!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard