Hi,
I am trying to create a simple document library sync between two libraries. Both the source and target libraries have the exact same folder structure. What I am trying to do is when a file is created/modified in the source library a flow triggers a copy process. Rather than having to create a flow for each folder, I am trying to manipulate the "Folder Path" of the file so that I can use it in the "Destination Folder" parameter with the "SharePoint Copy File" action.
Of course doing this means that the destination folder path ends up having both the source and target document library names in the path.
Is there a way I can strip out the source document library name from the "Folder Path" variable?
Thanks
Rob
Solved! Go to Solution.
Hey@Rob_CTL
Here's an extra expression to remove the last '/' .... I have tested and this works:
Compose: replace(variables('test'),'Source','Destination')
Compose 2: substring(outputs('Compose'),0,lastIndexOf(outputs('Compose'),'/'))
You'll obviously need to change the variables... you could of course nest these expressions into a single expression but I've done this for ease of reading / understanding what's happening
HTH
Jay
Hi @Rob_CTL
Yes, you can do this with the string replace expression, example: replace('Source Library/Reports','Source Library','Target Library')
This would return a value of: Target Library/Reports
HTH
Jay
-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up
@Jay-Encodian thanks for the information. That works well but doesn't quite do what I'm after as it fixes the destination folder to /reports. What I am trying to do is capture the path of the source file which might be in a sub folder then use that as the path for target (minus the source document library name) so the path is more dynamic.
Rob
Hi @Rob
You just need to substitute the values with dynamic data, for example: concat(body('Get_file_properties')?['{Path}'],'Source Library','Target Library')
When you're in the expression builder, click dynamic data and select the 'Folder Path' variable.
HTH
Jay
Thanks for your patience on this. I've put the command in as you suggested and the result:
So still not quite what I am looking to do, maybe I am over thinking this. All I am really trying to do is remove the first part of the folder path above so instead of it reading "Source Library/Reports" it is just "/Reports". If I can do that in a compose action and use the output to provide the copy file action it's folder path that would be brilliant.
Rob
Building on what @Jay-Encodian has provided I thought I could make this really simple and create a compose action with a simple replace function:
replace(body('Get_file_properties')?['{Path}'],'Source','Target')
That worked, well it successfully replaced the word "Source" in the folder path to "Target", but for some very odd reason when I use the compose output in the "Copy File" action "Destination Folder" it adds a / to the path
This leading / causes the flow to fail with the following error:
Failed to verify the existence of destination location at 'https://xxxxx.sharepoint.com/sites/test/Target Library/Reports/' due to error 'The system cannot find the file specified. (Exception from HRESULT: 0x80070002)'.
clientRequestId: 54032ecf-1c6e-4195-a1f7-f9b3e21019e1
serviceRequestId: 54032ecf-1c6e-4195-a1f7-f9b3e21019e1
That URL is valid in that I can copy it to a browser and it opens the document library. If I run the flow and select the folder by browsing to it the output doesn't have the / on the folder path and the flow completes.
Thanks in advance for any help.
Rob
Hey@Rob_CTL
Here's an extra expression to remove the last '/' .... I have tested and this works:
Compose: replace(variables('test'),'Source','Destination')
Compose 2: substring(outputs('Compose'),0,lastIndexOf(outputs('Compose'),'/'))
You'll obviously need to change the variables... you could of course nest these expressions into a single expression but I've done this for ease of reading / understanding what's happening
HTH
Jay
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!
User | Count |
---|---|
45 | |
43 | |
37 | |
34 | |
27 |
User | Count |
---|---|
48 | |
38 | |
32 | |
32 | |
31 |