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 / How to check if a fold...
Power Automate
Unanswered

How to check if a folder exists in SharePoint Document Library from a excel list

(0) ShareShare
ReportReport
Posted on by 10

Hello everyone.

I am posting this message to get help from you

 

I needed to move files from one library to another based on folder name, so I created a feed (see attached) . The flow works fine without errors. But the processing time is much too long because the library containing the folders has more than 2000 folders.

I would like to create an Excel table to optimise the processing time but I don't know how to do it.

 

merge_from_ofoct.png

 

Thank you for your help

Categories:
I have the same question (0)
  • eliotcole Profile Picture
    4,363 Moderator on at

    I'm not sure that Excel would be of help to you here, @Bibi ...

     

    Would I be right in assuming that you are looking to see if any of the folders listed have a name that either match es or contains a word that you have defined elsewhere?

     

    If so, you can drastically cut down your flow using a Filter action and a boolean Variable action.

     

    Don't take this too literally, I don't really know enough about your flow, because a lot of it is closed there.

     

    So, I have run the List folder action as you have, and after which I run a Filter action to see only return items in the list that are folders, and where their name contains 'General'. Just remember this is an example, you might use a dynamic value instead of the word "General" here.

     

    I use this expression by tapping on 'Edit in Advanced mode':

    @and(equals(item()?['IsFolder'], true), contains(item()?['Name'], 'General'))

    If I wanted that to look for an exact folder name, I would change 'contains' to 'equals'.

    basicBits.jpg

     

    After that, I initialize (or 'set') my boolean doesExistVAR with:

    greater(length(body('Filter_array')), 0)

    This does two things to confirm if my folder exists:

    1. length() - This counts the amount of items that the filter returns.
    2. greater() - This returns a true value if the length() is greater than 0.

     

    Since I can't see the key steps, this might not be an exact fix for your troubles, but if you approach your data in a like minded way, you will likely get similar results. 🙂

  • Bibi Profile Picture
    10 on at

    Hello @eliotcole 

     

    I would like to thank you for answering me on this subject

     

    I am sorry I did not put the key elements of the flow, so you will find attached the whole of my flow

     

    I have tried your solution but it does not solve my optimization problem because my loop looks for folder by folder and that according to the number of folders in the list, unfortunately I have more than 2000 which slows down the processing time a lot2021-11-08 17_40_56-Edit your flow _ Power Automate.png2021-11-08 17_42_09-Edit your flow _ Power Automate.png2021_11_08_17_42_23_Edit_your_flow_Power_Automate.png2021_11_08_17_44_14_Edit_your_flow_Power_Automate.png2021_11_08_17_45_23_Edit_your_flow_Power_Automate.png2021_11_08_17_46_28_Edit_your_flow_Power_Automate.png

     

  • eliotcole Profile Picture
    4,363 Moderator on at

    I think this is actually much easier, now, @Bibi ! 😅

     

    Before I thought you needed to find a folder, but it is actually a file, and you have already defined where that is, so I think we can (together) simplify your flow by a lot! Give me some time, I'll sort something out. 👍

  • eliotcole Profile Picture
    4,363 Moderator on at

    @Bibi a couple more questions:

    1. Are you using the List folder action to ensure that the file has been made correctly?
    2. Are you then copying the same email to a client folder?
    3. Is NumeroSapObjet counting the amount of characters in the subject of the email? Or is it the size of the file that it has created?
    4. Similarly, is NumeroSapDossier counting the amount of characters in the subject of the document file that you create?
    5. Actually if you could copy these expressions here, that would be useful:
      1. In NumeroSapObjet the trim() expression.
      2. In List folder, the encodeUriComponent() expression.
      3. In NumeroSapDossier the trim() expression.

    Finally, a recommendation for your library data in your 'Email' library. For the Corps Du Mail column, you should not use 'body' from the email, you should use 'Body'. That is just the message text, then, rather than the whole email details. If you are already storing the whole email, it does not make sense to replicate it in the metadata. 

     

    ---

     

    If the answer to my first question is 'Yes' then you do not need to do this. If the creation fails, then the flow will fail, and you will be notified according to your notification preferences.

     

    However, if you still want to be sure, then you can create 'Error reporting' using failure branches that use the 'Run after' settings for an action. You do this by:

    1. Create a parallel branch with an an action inside it (I usually increment an integer variable).
    2. Go to the action '...' menu and select 'Configure run after'.
      runAfter01.jpg

       

    3. Check only the 'Has failed' option and tap 'Done'.
    4. Now join your branches with an action.
    5. This must run whatever happens in both branches. So;
      1. ... tap 'Configure run after' once, marking all the options, then tap 'Done',
      2. ... then tap 'Configure run after' again, but select the other action on the left, then mark all the options, and tap 'Done'.

    runAfter02.jpg

     

    This isn't a solution, just a helpful thing for complex flows. Try to play with it in test flows if you like.

     

    Now, later on in the flow this is from I can check the number of errors, and if they are higher than 0 I know that this failed, and I can send myself a message to check in on the flow. 👍

  • eliotcole Profile Picture
    4,363 Moderator on at

    Two Solutions !

    One - Simple Flow (mostly)

    simpleIshFlow-minimised.jpg

     

     

    This just finds the folder and makes the files. If there are any errors you rely on flow notifications to tell you.

     

    Here it is spanned out:

    simpleIshFlow.jpg

    Variable clientFolderVAR

    This will hold the path to the client's folder.

     

    Constants

    emailSubjectCON is not strictly necessary, but it's just there because I wanted it. emailBody has the following expression, but obviously you should ensure your references are correct if you want to use this:

     

    if(triggerOutputs()?['body/isHtml'], outputs('Html_to_text_on_the_email_Body')?['body'], triggerOutputs()?['body/body'])

     

    fullFlow03-Constants.jpg

    Note:

    1. There is an HTML to Text on the email message/Body? This way it means that the column in the libraries will not be full of HTML if the trigger field 'isHtml' equals true.
    2. I should have named the emailBody constant 'emailBodyCON' for continuity.

     

    Folder Management (folderChecker)

    Inside the folderChecker scope I made Filter clientFolders which provides a list of folders that have the correct client number (clientNumCON). This results in this Filter action should 1 item if it exists, or 0 if it does not.

     

    So, then there is Condition to see if the number of results in Filter clientFolders is equal to 1. To count the results in the filter the expression is:

     

     

    length(body('Filter_clientFolders'))

     

     

    Yes branch

    If there is one result then the clientFolderVAR is set to the 'Full path' key from the first item [0] in the Filter clientFolders array with:

    body('Filter_clientFolders')[0]?['Path']

    No branch

    If there's zero results (because there can't be more) this branch will run, and will make the folder, then provide the clientFolderVAR with the 'Full Path' field from the Create new folder in clients library action.

     

    -----

    -----

    Two - Error Tracking

    I have updated this one to show the simplicity of the file creation logic.

     

    This Error Tracking flow will only fail if a file creation fails, and you will have details of where it failed, too. You can then add more steps into the flow and track more errors if need be. 

    fullFlow01-Complex.jpg

     

     

    More detail

    I'm sure you can see that there is more going on here.

     

    Variables & Constants

    First of all, here are the variables, there's the new clientFolderVAR and currently pointless folderOkVAR, plus there are also now integer counts for errors when making the files with clientLibraryErrVAR, emailLibraryErrVAR, and renamed totalErrorsVAR.

    fullFlow02-Variables.jpg

     

    The constants are unchanged from the simple flow.

     

    Folder Management

    This expands on the simple version, except that I have realised that the folderOkVAR is utterly pointless at the moment, so you don't need that.

     

    fullFlow04-FolderChecker.jpg

     

     

     

    File Creation

    I have made this branched, with their own error counts to indicate more specific failures, I also added your fields (kind of 😉). Also, this now uses the new clientFolderVAR.

    fullFlow05-AddFiles.jpg

    • Title is the outputs of emailSubjectCON.
    • clientNum is the outputs of clientNumCON.
    • emailBody is the outputs of emailBody.

     

    Error Reporting

    Finally, any error reporting is sent, or the flow finishes successfully.

    fullFlow06-EndingFairy.jpg

    Note - The only expression here is just adding the two variable counts together in the totalErrorsVAR.

    expression

     

     

     

    add(variables('emailLibraryErrVAR'), variables('clientLibraryErrVAR'))

     

     

     

  • Bibi Profile Picture
    10 on at

    Hello @eliotcole ,

     

    I thank you very much for the time you give me, you are great

     

    - I use "ListFolder" to list and retrieve the folders in a library

     

    - The idea of the flow in general is to recover an email being in a library "Email" and to redirect it automatically towards the customer folder which corresponds to him according to the name of the email (the object of the email), for example if the object of the email sent is "toto - 73883 - abc", I get the second element which is 73883 and I look among the list of the folders the one which contains the number 73883 and I put it in

     

    - The NuméroSAPObjet contains the following expression to retrieve the second element of the email subject:
    trim(split(outputs('OBJECT'), '-')[1])

     

    - The NumeroSAPDossier contains the following expression to retrieve the second element of the folder name as well, as we have folders whose name is the client's name and a number:
    trim(split(outputs('Compose'), '-')[1])

     

    - As explained before, in "ListFolders" I get the list of folders from a specific path:
    encodeUriComponent('/Shared Documents/Clients/')

  • eliotcole Profile Picture
    4,363 Moderator on at

    Cheers, @Bibi! I will edit the solution above, just give me a few minutes.

     

    Also, I think I have a couple of points to make, if you don't mind. 🙂

     

    ----

    General Logic on Files

    A quick note about a big part of your logic, more specifically you do not need to do this part: 🙂

    recover an email being in a library "Email" 


    Because you have literally just created that file, you don't need to go get it. You can either just make another at the same time, or copy the file that you just made. 👍

     

    Anyway, we still don't need to use the Apply to each, a Filter action will help here.

    ----

     

    Client Identification / Separator in the Object (Subject)

    It's a shame that you use the hyphen '-' as the separator, because this can be used a lot in the subject line which could affect handling this further down the line.

     

    I think that there are two ways to handle this:

    1. SharePoint List

    If all of your clients have different email addresses, then you might be better off making a SharePoint list with 4 columns:

    1. Email
    2. Client
    3. ClientNum
    4. Folder

    Then lookup the client number on the list, and use the Folder field.

     

    2. Create a clients Library and Client Number Column

    For now I think this option is a much better thing for you to do. Even if you do not want to create a separate 'clients' library you should definitely make a ClientNum column in the relevant SharePoint Libraries, as it will assist things in the future.

     

    Anyway, if you have a clients library, then your folders are not restricted by the Shared Documents\general library settings, that might have other stuff going on. You can also then assign different privileges, add more columns, loads of stuff. It should not be too hard to just move all the client folders into a clients library.

  • eliotcole Profile Picture
    4,363 Moderator on at

    OK, @Bibi, it should be good to go, now.

     

    I guess the key thing is understanding that you can use a Filter action like a kind of merge of a Condition and an Apply to each.

  • Bibi Profile Picture
    10 on at

    Hello @eliotcole ,

     

    Your solution seems to me much more useful and understandable.

     

    However, there are two elements that are still confusing, I refer to the "continueEmailsLib" and the "continueClientsLib", what are they used for ? what is inside ?

     

    Thank you so much

  • eliotcole Profile Picture
    4,363 Moderator on at

    Hi, @Bibi , hehehe 😅 I actually think the 'Lib' part is a mistaken spelling of something else.

     

    Anyway, if you look at one of my previous posts above you can see the meaning of them. They 'close' the error condition.

     

    So, the 'continue' ones are just two normal Compose actions, however they have 'Run after' settings so that they will  run even if the failure branch runs.

     

    If you scroll up to this post, you will see where I quickly explained basic error handling in a flow.

     

    Although, like I've said, you probably don't need it. I just saw that you were being super cautious about files being created and thought that I would offer that as a second option.

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 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard