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?
@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
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
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.
Thank you for this helpful video. When i run it to show all empty folders, it just get an empty list with [ ]. If i change it to list all of the folders with contents, it works fine and lists all of those folders perfectly. I do this by changing the condition form 'true' to 'false'. Why is it not returning anything when i have it set to 'true'. (yes I have lots of empty folders so thats not the reason. :)
@@christopherway5765 without seeing your flow it's a bit hard, but I'll try to help. First, if your document library is really large and the output of the "get files" action is larger than 5000 items, there's a possibility that all your empty folders are beyond item 5000 and therefore do not show up. You would need to increase the output with pagination or with a loop. Depending on your power automate license. Second, sometimes if you write simply "true" in the condition it can output a wrong outcome. Instead insert a function and write in there "true". I've made a short about this: th-cam.com/users/shortsJNG2SX5PDcc?si=yDxFjPaMV0p4HG-5
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?
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?
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?
@@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!
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?
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
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 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.
Thanks for sharing the video; very helpful!
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?
@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
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
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.
Thank you for this helpful video. When i run it to show all empty folders, it just get an empty list with [ ]. If i change it to list all of the folders with contents, it works fine and lists all of those folders perfectly. I do this by changing the condition form 'true' to 'false'. Why is it not returning anything when i have it set to 'true'. (yes I have lots of empty folders so thats not the reason. :)
@@christopherway5765 without seeing your flow it's a bit hard, but I'll try to help. First, if your document library is really large and the output of the "get files" action is larger than 5000 items, there's a possibility that all your empty folders are beyond item 5000 and therefore do not show up. You would need to increase the output with pagination or with a loop. Depending on your power automate license.
Second, sometimes if you write simply "true" in the condition it can output a wrong outcome. Instead insert a function and write in there "true". I've made a short about this: th-cam.com/users/shortsJNG2SX5PDcc?si=yDxFjPaMV0p4HG-5
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?
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?
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?
@@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!
I had the same problem. The solution was creating the flow in the old interface (the new one creates another type of expressions).
Hey Markus it works awesome but what about subfolders?
Hi! This will give you all the empty folders of this library, including empty subfolders
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?
Did you name the action differently, or are you using power automate in a different language?
@@MarkusSchiller Hi, same name. Power Autonomate in Portuguese.
@@antonioviana4476 it's hard to say without seeing the actual flow, but it seems like you have somewhere a name mismatch
I had this issue too. I changed the language for Power Automate to English and then it worked fine.
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
@@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
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
Hi! I will test it and will get back to you 🙂
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
@@MarkusSchiller thanks !!! Will you be able to post that solution ?
@@AbbyRani Hi Vidhya, it took a bit longer but here's the video: th-cam.com/video/45OVGDW21wU/w-d-xo.html
Could you do a tutorial on how to mirror a folder and its contents into another library?
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?
@@MarkusSchiller Ideally a real sync. Maybe it's not possible. I haven't been able to get it to work.
@@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.
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
Did you set "include nested items" to "no" in the action "get files (properties only)"?
Need to empty a specific folder via cloud flow.