cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
anzy91
Helper I
Helper I

How Can I Create Folders And Sub Folders In SharePoint Library Using Power Automate

Hello, 

 

Hope you're well 🙂

 

I would like to know how I can use power automate to create folders and subfolders in the SharePoint library.

 

below is my document library in SharePoint

anzy91_0-1642061690477.png

 

I want to add subfolders to each folder in the document library automatically.

anzy91_1-1642061802133.png

 

 Could I please know what is the best way to do this using power automate?

 

 

12 REPLIES 12
Expiscornovus
Dual Super User
Dual Super User

Hi @anzy91,

 

Do you want to create these folders only one time. Or is this something you want to schedule?

 

For the first scenario you could use a setup like below.

This setup uses an array for all the subfolders. It also retrieves the current folders in the first level. It loops through those folders and creates the 5 sub folders per folder item found in the root of the library.

 

However, it doesn't check if the subfolders already exist. So, this setup would only support a one-time creation scenario.

 

createsubfolders.png

 

1. Add initialize variable action of type array, call it SubFolders. Use the array below as a value.

 

 

 

[{
    "SubFolder": "1. NDA"
  },
  {
    "SubFolder": "2. Contract Documents"
  },
  {
    "SubFolder": "3. Due Diligence"
  },
  {
    "SubFolder": "4. Emails"
  },
  {
    "SubFolder": "5. Purchase Orders"
  }]

 

 

 

subfolders_array.png

 

2. Add a get files (properties only) action. Make sure you select No to not include nested items.

 

3. Add a Filter Array action. Use the value of the previous action. Make sure you filter on IsFolder eq true. Otherwise the flow will also use documents in the loop.

 

getfilesonly.png

 

4. Add an apply to each action. Use the body of the Filter Array action.

 

5. Add another apply to each action within the first apply to each. Use the SubFolders array.

 

6. Add a Create New Folder action.

 

Use the following expression for the Folder Path field:

 

 

concat(items('Apply_to_each')?['{Name}'], '/', item()['SubFolder'])

 

 

 

applytoeachnested.png

 

@Expiscornovus Thank you for your reply I appreciate it :). I will get back to you once I give it try. 

anzy91
Helper I
Helper I

@Expiscornovus To start the flow process do I use:

anzy91_0-1642071798025.png

 

Expiscornovus
Dual Super User
Dual Super User

Hi @anzy91,

 

Sorry, I cropped my first screenshot by accident 😁

 

I used the Manually trigger a flow action. That is the easiest action if you only want to run it once.

 

manuallytriggerflow.png

 

 

@Expiscornovus I'll give it a try

anzy91
Helper I
Helper I

@Expiscornovus I got it working now 🙂 Thank you for your help 

anzy91_2-1642087654027.png

 

anzy91_0-1642087203611.pnganzy91_1-1642087227665.png

 

what is the process of getting it scheduled?

 

Is there a way to check if subfolders already exist in the document library?

 

Kind regards,

Anees

anzy91
Helper I
Helper I

@Expiscornovus 

Hey hope you're well 🙂

what is the process for automating the flow instead of using the manual trigger?

Expiscornovus
Dual Super User
Dual Super User

Hi @anzy91,

 

Instead of the manually trigger a flow action you could use a recurrence trigger action and define a schedule.

 

recurrence.png

 

For the check part of your question I would use a mechanism to retrieve the folder just before the create folder action in the loop.

 

With a condition you could check if the output is empty. If that is the case you could put the Create folder action within the if Yes.

@Expiscornovus thank you for your reply 🙂

Do you have an example that I can see or follow.

Expiscornovus
Dual Super User
Dual Super User

Hi @anzy91,

 

Yes, sure. I can share an example about that. See below.

 

1. First of all I would use a filter query to match your recurrence action. Let's say you configure it to run the flow once a week. I would filter the Get files so it only retrieves folders which have been created in the past 7 days.

 

Created ge '@{formatdatetime(addDays(utcNow(), -7), 'o')}'

 

filterquery_created.png

2. In the apply to each I would add a Get folder metadata using path action. Put the name of the name of the library in the value and use the same concat function we use in the Create folder action.

LibraryCreateSubFolders/@{concat(items('Apply_to_each')?['{Name}'], '/', item()['SubFolder'])}

 

3. Add a condition action. In the settings of action make sure it also runs when the previous action has failed. Use the configure run after setting for that.

 

4. In the condition check if the message is not empty and that the message starts with Folder not found.

 

5. Add the Create new folder to If Yes.

 

 

checkfolders.png

anzy91
Helper I
Helper I

@Expiscornovus Thank you :). I will have a go trying out the process. 

Good morning, this setup is something I need, but I need extend the setup with the specific Channel or folder name. So A would have Folder 1, 2, 3 and B should have something like 5, 6, 7. So I need to check the name of the base folder A and on that basis I need to add folders. Can we think of a working process for that. I need to create 6 unique channels and consequently 6 various folders in there. 

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

New Process Advisor Capabilities carousel.png

Read the blog for the latest news

Read the latest about new experiences and capabilities in the Power Automate product blog.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

AI Builder AMA June 7th carousel (up on May 25th, take down June 8th) (1).png

'Ask Microsoft Anything' about AI Builder!

The AI Builder team invite you to ask questions and provide helpful answers at our next AMA.

Users online (1,587)