The simplest way to do this, without much coding but still able to be updated easily, is to use the following Flow:
Here's a breakdown, action by action.
Step 1: Set up an array variable that will hold our folder names and the associated email recipients
Here's that array to copy/paste into your flow. Be sure to set the email recipients and folder names based on your environment:
[
{
"Recipient": "emailrecipient1@contoso.com",
"Folder": "Shared Documents/General/TestFolder1/"
},
{
"Recipient": "emailrecipient2@contoso.com",
"Folder": "Shared Documents/General/TestFolder2/"
},
{
"Recipient": "emailrecipient3@contoso.com",
"Folder": "Shared Documents/General/TestFolder3/"
},
{
"Recipient": "emailrecipient1@contoso.com",
"Folder": "Shared Documents/General/TestFolder4/"
},
{
"Recipient": "emailrecipient2@contoso.com",
"Folder": "Shared Documents/General/TestFolder5/"
},
{
"Recipient": "emailrecipient3@contoso.com",
"Folder": "Shared Documents/General/TestFolder6/"
},
{
"Recipient": "emailrecipient1@contoso.com;emailrecipient2@contoso.com",
"Folder": "Shared Documents/General/TestFolder7/"
},
{
"Recipient": "emailrecipient2@contoso.com;emailrecipient3@contoso.com",
"Folder": "Shared Documents/General/TestFolder8/"
}
]
Step 2: Set up a string variable and leave it blank
Step 3: Apply To Each using the array variable we set up in step 1
Step 3a: Inside the Apply To Each loop, add a Condition checking the folder that's had a file created or modified against the current folder in our array
On the left side you can copy/paste this: @{triggerBody()?['{Path}']}
On the right side, you'll copy/paste this: @{items('Apply_to_each')?['Folder']}
Step 3a1: Inside the If True box, use an Append to String Variable action to add the recipient's email address to the string variable from step 2
Step 4: Outside of the Apply To Each we'll use a second Condition to make sure we have at least one recipient. This way if a new folder is added to the directory but not the array, the flow will send an email to a default person:
That expression on the left is: @{length(variables('strRecipient'))}
Step 4a: Inside the If True box, use an Append to String Variable action to add a default recipient email address
Step 5: Now we send the email, setting the Recipients box to use our String variable
A couple quick notes:
1. The array example given shows how to send the email to multiple users for a single folder
2. If you want to add folders or change recipients, you'll only have to edit the array variable
3. To get the full folder name, you'll want to check a completed flow run's trigger outputs for the {Path} value. From that, you'll be able to easily replicate the structure for all folders in your target directory: