cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Petr_Marek
Regular Visitor

Sync two folder in one SharePoint Site reversibly

Dear all,

 

I have an issue. I need to full snyc files from one folder to another in the same library (We use Teams from O365) using Microsoft Flow

Example :

  • I have folder WORKING and SHARED
  • I can make flow that copy files when created or modified in one way -> Copy files from WORKING to SHARED.
  • But when I try to create second flow to copy files from SHARED to WORKING, I have problem that files are beeing copy in the cycle.

Can you advise me If exist way to make one flow or two flows between two folders for full sync it ?

3 REPLIES 3
v-xida-msft
Community Support
Community Support

Hi @Petr_Marek,

 

If you want to avoid the Sync cycling, you should consider check if the file has existed in the corresponding folder of a SharePoint library, if it has existed, we could not copy the file to this folder from another folder.

 

I have made a test on my side and please take a try with the following workaround:

  • Copy files from WORKING folder to SHARED folder:
  1. Add a "When a file is created or modified (properties only)" trigger, specify Site Address and Library Name, Folder field set to WORKING folder.
  2. Add a "Get file metadata" action, specify Site Address and File Identifier field set to Identifier dynamic content of the trigger.
  3. Add a "Get file content" action, specify Site Address and File Identifier field set to Identifier dynamic content of the trigger.
  4. Add a "Get files (properties only)" action, specify Site Address and Library Name.
  5. Add a "Filter array" action, From set to output of "Get files (properties only)" action, click "Edit in advanced mode", type the following formula:

 

@equals(item()?['{Path}'], 'MyLibrary2/SHARED/')

 

     6. Add a Variables-> "Initialize variable" aciton, Name set to OriginalFileArray, Type set to Array and Value set to empty.

     7. Add a "Apply to each" action, input parameter set to output of "Filter array" action. Within "Apply to each", add a "Get file metadata 2" action, specify Site Address, File Identifier field set to following formula:

items('Apply_to_each')?['{Identifier}']

Add a "Append to array variable" action, Name choose OriginalFileArray and Value set to DisplayName dynamic content of "Get file metadata 2" action.

 

   8. Under "Apply to each", add a Condition, click "Edit in advanced mode", type the following formula:

@contains(variables('OriginalFileArray'), body('Get_file_metadata')?['DisplayName'])

   9. Within "If/no" branch of Condition, add a "Create file" action, specify Site Address and Folder Path. File Name field set to DisplayName dynamic content of "Get file metadata" action, File content field set to File Content dynamic content of "Get file content" action.

 

Image reference:24.JPG

 

25.JPG

 

26.JPG

The flow works successfully as below:27.JPG

 

 

  • Copy files from SHARED folder to WORKING folder:
  1. Add a "When a file is created or modified (properties only)" trigger, specify Site Address and Library Name, Folder field set to SHARED folder.
  2. Add a "Get file metadata" action, specify Site Address and File Identifier field set to Identifier dynamic content of the trigger.
  3. Add a "Get file content" action, specify Site Address and File Identifier field set to Identifier dynamic content of the trigger.
  4. Add a "Get files (properties only)" action, specify Site Address and Library Name.
  5. Add a "Filter array" action, From set to output of "Get files (properties only)" action, click "Edit in advanced mode", type the following formula:

 

@equals(item()?['{Path}'], 'MyLibrary2/WORKING/')

     6. Add a Variables-> "Initialize variable" action, Name set to OriginalFileArray, Type set to Array and Value set to empty.

     7. Add a "Apply to each" action, input parameter set to output of "Filter array" action. Within "Apply to each", add a "Get file metadata 2" action, specify Site Address, File Identifier field set to following formula:

 

items('Apply_to_each')?['{Identifier}']

 

Add a "Append to array variable" action, Name choose OriginalFileArray and Value set to DisplayName dynamic content of "Get file metadata 2" action.

 

   8. Under "Apply to each", add a Condition, click "Edit in advanced mode", type the following formula:

 

@contains(variables('OriginalFileArray'), body('Get_file_metadata')?['DisplayName'])

   9. Within "If/no" branch of Condition, add a "Create file" action, specify Site Address and Folder Path. File Name field set to DisplayName dynamic content of "Get file metadata" action, File content field set to File Content dynamic content of "Get file content" action.

 

Image reference:28.JPG

 

29.JPG

 

30.JPG

The flow works successfully as below:31.JPG

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-xida-msft

 

thank you for your instructions. I will try it and send you feedback.

 

Thaks' Petr Marek

Hi @v-xida-msft ,

 

I've tried to borrow this idea but it seems the "edit in advanced mode" has been changed to expression in Condition.

Then I made it OriginalFileArray contains Body AND OriginalFileArray contains DisplayName but failed.

 

 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,369)