cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JKlusacek
Frequent Visitor

Automatic creation of a structure in a new folder

Hello, I would like to ask. Is it possible to create a flow that would automatically create a folder structure in the newly created folder? Example:

1) The user creates a folder (custom content type) with the project name: yyyy_nnnn_Project name

2) when this folder is created, a flow would be started that it will copy (from the template) or create the structure of the project.

The structure of the folders is:  

folder 1

folder 2

            subfolder 2.1

            subfolder 2.2 

            subfolder 2.3

                                  subfolder2.3.1

                                  subfolder2.3.2

folder 3 

 

Is there a solution for this flow?

Thanks a lot

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @JKlusacek,

 

This would be possible via an array and the create new folder action.

 

However, because you are also triggering on new folder creation we need some additional logic to prevent the flow going into a continuous loop.

 

Below is an example of that approach.

 

1. Add the following expression as a trigger condition into the settings of the When a file is created trigger action.

This condition is to check if the newly created file is a folder and if it starts with '2021_' in the name. This way the newly created subfolders will be ignored. 

Another approach would be to use a service account in the connection. This way you can ignore the newly created folders if the service account is the author.

 

@and(triggerOutputs()?['body/{IsFolder}'], startswith(triggerOutputs()?['body/{Name}'], concat(formatDateTime(UtcNow(), 'yyyy'), '_')))

 

triggercondition_folder_2021.png

 

2. Initialize an array variable action. Use the following value for it

 

[
  "folder 1",
  "folder 2",
  "folder 2/subfolder 2.1",
  "folder 2/subfolder 2.2",
  "folder 2/subfolder 2.3",
  "folder 2/subfolder 2.3/subfolder 2.3.1",
  "folder 2/subfolder 2.3/subfolder 2.3.2",
  "folder3"
]

 

3. Loop through the array with an apply to each action. Place a create new folder action within the apply to each action. Use the name and item of the array for the Folder Path column:

 

@{triggerOutputs()?['body/{Name}']}/@{item()}

 

createfoldersinbulk.png

View solution in original post

4 REPLIES 4
Expiscornovus
Super User
Super User

Hi @JKlusacek,

 

This would be possible via an array and the create new folder action.

 

However, because you are also triggering on new folder creation we need some additional logic to prevent the flow going into a continuous loop.

 

Below is an example of that approach.

 

1. Add the following expression as a trigger condition into the settings of the When a file is created trigger action.

This condition is to check if the newly created file is a folder and if it starts with '2021_' in the name. This way the newly created subfolders will be ignored. 

Another approach would be to use a service account in the connection. This way you can ignore the newly created folders if the service account is the author.

 

@and(triggerOutputs()?['body/{IsFolder}'], startswith(triggerOutputs()?['body/{Name}'], concat(formatDateTime(UtcNow(), 'yyyy'), '_')))

 

triggercondition_folder_2021.png

 

2. Initialize an array variable action. Use the following value for it

 

[
  "folder 1",
  "folder 2",
  "folder 2/subfolder 2.1",
  "folder 2/subfolder 2.2",
  "folder 2/subfolder 2.3",
  "folder 2/subfolder 2.3/subfolder 2.3.1",
  "folder 2/subfolder 2.3/subfolder 2.3.2",
  "folder3"
]

 

3. Loop through the array with an apply to each action. Place a create new folder action within the apply to each action. Use the name and item of the array for the Folder Path column:

 

@{triggerOutputs()?['body/{Name}']}/@{item()}

 

createfoldersinbulk.png

View solution in original post

Hi @Expiscornovus ,

thank you very much. Flow is functional. I still hve a problem with the anti-cycling condition. Is it possible to set that the folder starts with a number in the range 2000 - 3000?

Thanks a lot

Expiscornovus
Super User
Super User

Hi @JKlusacek,

 

With that design/approach you could try and use the trigger condition below

 

@and(and(greaterOrEquals(int(substring(triggerOutputs()?['body/{Name}'], 0, 4)), 2000),lessOrEquals(int(substring(triggerOutputs()?['body/{Name}'], 0, 4)), 3000)), triggerOutputs()?['body/{IsFolder}'])

 

In this condition I am using a substring to collect the first 4 characters of the folder name. That value is converted to an integer and then compared to the integers 2000 (greater or equals) and 3000 (less or equals). 

@Expiscornovus 

 

Thank you so much.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,779)