PowerAutomate: Get all empty folders from a document library

Поделиться
HTML-код
  • Опубликовано: 20 окт 2024

Комментарии • 31

  • @jt9228
    @jt9228 7 месяцев назад +1

    Thanks for sharing the video; very helpful!

  • @JillKeogh1995
    @JillKeogh1995 Месяц назад +1

    Great video! Thank you for your time! I am having issues with the Output information. The Output is the same as the Input. And the results are not pulling the empty folders. Any suggestions as to what I'm doing wrong?

    • @MarkusSchiller
      @MarkusSchiller  Месяц назад +1

      @JillKeogh1995 Hi! Well, in this case the last "compose" action is simply to visualise the output of the array. If you say the array is empty then there is probably a catch in the condition. Instead of writing "True" insert the expression True. In my newest video I have made a newer version of this flow, which you could adapt to your needs

  • @BryanMendez120
    @BryanMendez120 4 месяца назад +1

    Hi Markus, what if my sharepoint site has more than 50k empty folders? Can this flow still get that info? also, How can I put that empty folder path within an Excel Sheet? Many Thanks

    • @MarkusSchiller
      @MarkusSchiller  4 месяца назад +1

      Hi Bryan, well 50k+ is definitely a large number and you'll have to fight some PowerAutomate limits as an "Apply to each" loop can only inherit a maximum of 5000 items. You would need two helper variables. One for the Item ID. Each item in a document library gets an ID. So if you have 50k items in your library, then you probably have IDs from 1-50001 and so on. Lets say the variable is named "itemId" and is set initially to 0. The second helper variable would be "breakLoop" and is a boolean and is set initially to false.
      First you would need to wrap the "Get files (properties only)" and the "Apply to each" action in a "Do until" action.
      Then you would need to modify the filter query of the action "Get files (properties only)" to: "FSObjType eq 1 and ID gt @{variables('itemId')}". Order By "ID". Top Count "5000". That should give you the first 5000 items, where the ID is greater than 0. Then the "Apply to each" action is coming and deletes all the empty folders it can find. After the "Apply to each" action you could insert a "Condition" action, where you can check the output of "Get files (properties only)". If the array is empty, you can set the variable "breakLoop" to true. That is your breakout condition of the "Do until" loop, if the action doesn't find any more items in the document library. If the output is NOT empty, then you would need to increase the variable "itemId" by 5000.
      That way the "Do until" action will continue to loop and in the next round it will search for all items in the library that have an ID greater than 5000, in the next loop greater than 10000 and so on. With this, you can basically loop through the whole library.
      There is a catch though. It will probably take long and if you delete an empty subfolder within another folder, then the parent folder might become empty and so on... so you might need to trigger this flow also more often. I hope it makes sense and is halfway understandable what I've written.

  • @samirmalik8594
    @samirmalik8594 2 месяца назад

    hi
    How to check nested folders also.
    I want to check empty folder with below structure
    Folder 1
    subfolder level1
    subfolder level2
    subfolder level 2
    subfolder level 3
    Folder 2
    subfolder level1
    subfolder level2
    subfolder level 2
    subfolder level 3
    Folder 3
    subfolder level1
    subfolder level 3

    • @MarkusSchiller
      @MarkusSchiller  2 месяца назад

      @@samirmalik8594 Hi, the flow will check all the folders in the whole library, except if you have checked the option to limit it to a certain folder

  • @antonioviana4476
    @antonioviana4476 2 года назад +1

    Hi, thanks for the vídeo. I have this error ""The template validation failed: 'The action(s) 'List_folder' referenced by 'inputs' in action 'Condition' are not defined in the template.'."."
    I'm use this "empty(body('List_folder'))". Any solution?

    • @MarkusSchiller
      @MarkusSchiller  2 года назад

      Did you name the action differently, or are you using power automate in a different language?

    • @antonioviana4476
      @antonioviana4476 2 года назад

      @@MarkusSchiller Hi, same name. Power Autonomate in Portuguese.

    • @MarkusSchiller
      @MarkusSchiller  2 года назад

      @@antonioviana4476 it's hard to say without seeing the actual flow, but it seems like you have somewhere a name mismatch

    • @Oebbie
      @Oebbie 11 месяцев назад

      I had this issue too. I changed the language for Power Automate to English and then it worked fine.

  • @roblewis246
    @roblewis246 8 месяцев назад

    HI, thanks for making this video, unforetunetly when I try to run it all the folders go down the 'if no' path - even the empty folders. I can see in the run history that the body of the folder is [] but the empty(body('List_folder')) is not showing as true.
    Any ideas on how to troubleshoot?

    • @MarkusSchiller
      @MarkusSchiller  8 месяцев назад +1

      I see, it's a bit hard if I don't see your flow in front of me, but I can try. So, you have your "Apply to each" loop and the first action is the "List folder" action. And if you cycle through each iteration you can see that some of them have an empty body [] and some don't.
      And after the "List folder" action, you have a condition with empty(body('List_folder')) is equal to false.
      In this condition you have a true path to the left, which will append to the array variable and a false path to the right, which is empty.
      I know, I could have made it the other way around, but maybe that's where some things got mixed up?

    • @MarkusSchiller
      @MarkusSchiller  8 месяцев назад +1

      Hi again, so I must have changed something in my old workflow for test purposes. Of course the condition should be "empty(body('List_folder')) is equal to true". I've tried it again and it works, but I've noticed that in some cases the word "true" can cause some problems. Instead, you can add an expression which simply says "true" and then it will make the pink expression background around it.
      Otherwise it should work. Did you maybe rename one of the actions?

    • @roblewis246
      @roblewis246 8 месяцев назад

      @@MarkusSchiller Hi, the tip around adding the true condition as expression has resolved the issue. I was also having an issue with the JSON in the append action but this was caused by the new editor adding a for each loop after the condition action which messed the references up.
      Thanks for you help with this!

    • @RafaelZampieron
      @RafaelZampieron 8 месяцев назад

      I had the same problem. The solution was creating the flow in the old interface (the new one creates another type of expressions).

  • @vincentebel3091
    @vincentebel3091 Год назад

    Does'nt work for me. It gets only empty folders in an only folder in the library and gives me no result for other directories which have empty folders

    • @MarkusSchiller
      @MarkusSchiller  Год назад

      Did you set "include nested items" to "no" in the action "get files (properties only)"?

  • @saleemsowkath2428
    @saleemsowkath2428 2 года назад

    Need to empty a specific folder via cloud flow.

  • @drpeg66
    @drpeg66 Год назад

    Hey Markus it works awesome but what about subfolders?

    • @MarkusSchiller
      @MarkusSchiller  Год назад

      Hi! This will give you all the empty folders of this library, including empty subfolders

  • @AbbyRani
    @AbbyRani 2 года назад

    Hi I have used flow I’m getting empty folder but still I have a folders which has three sub folders in it and one of them has file , I want to delete empty folders and keep the folders which has files any other condition I have to use

    • @MarkusSchiller
      @MarkusSchiller  2 года назад

      Hi! I will test it and will get back to you 🙂

    • @MarkusSchiller
      @MarkusSchiller  2 года назад

      I have found a solution. It's a bit tricky, because you'll need to use delete item and the ID and can't use the delete file action and the identifier

    • @AbbyRani
      @AbbyRani 2 года назад

      @@MarkusSchiller thanks !!! Will you be able to post that solution ?

    • @MarkusSchiller
      @MarkusSchiller  2 года назад

      @@AbbyRani Hi Vidhya, it took a bit longer but here's the video: ruclips.net/video/45OVGDW21wU/видео.html

  • @wrm8460
    @wrm8460 Год назад

    Could you do a tutorial on how to mirror a folder and its contents into another library?

    • @MarkusSchiller
      @MarkusSchiller  Год назад +1

      Hi! What do you mean exactly by mirror? Do you mean just a simple copy of a folder and its contents, or a real mirror that syncs every change (create, update, delete) of the contents?

    • @wrm8460
      @wrm8460 Год назад

      @@MarkusSchiller Ideally a real sync. Maybe it's not possible. I haven't been able to get it to work.

    • @MarkusSchiller
      @MarkusSchiller  Год назад +1

      @@wrm8460 with power automate you will run into multiple problems, because it's not meant for this kind of task. Let's say you want to have a sync on the updates of a file. SharePoint sometimes locks the file for a period of time internally so it can happen that the flow fails because it can't access the contents. If you have a lot of updates you could also run into some limitations of how many flows are allowed to run depending on your service plan.
      A daily backup would be possible, but power automate is not the right tool for a real sync.