Reputation: 3
So... I have an automated flow that copies files from a folder in one SharePoint site into a target folder in another site (same tenant). It is set to exclude a particular file type during copy using basically a for each loop. However, because I only have the one loop, it only does it for the root folder. How do I get it to dynamically work through nested folders? The source folder will get more folders in the future, and I would like to set the flow to run once a day.
The flow looks kinda like this:
Manually trigger a flow (for testing the flow before automating it)
List folder
Apply for each
Condition
file does not end with .pdf (for example)
Current Site Address entered File to Copy: Id from List folder Destination Site Address entered Destination Folder entered If Another File is Already There: Replace
It took me a while to get that bit to work, then I realised it wasn't iterating through the nested folders so the "pdfs" were still being copied.
Any ideas? Did I completely choose the wrong options in the flow?
Upvotes: 0
Views: 307
Reputation: 111
So it sounds like you need to essentially duplicate the contents of a document library from one SharePoint site into another, excluding PDFs. The setup you have now is good all you really need to do is add another condition that checks whether the items is a folder or not, and then create the file/folder appropriately. Luckily, a recursive solution is not necessary.
The following is a general description of a flow that will copy all files (including folder structure and excluding PDFs) from one SharePoint site's document library to another SharePoint site's document library:
<the name of the document library you are copying files from>
<the name of the document library you are copying files to>
<the URL of the site you are copying files from>
strTemplateLibraryName
outputs('Get_files_(properties_only)')?['body/value']
items('Apply_to_each')?['{IsFolder}'] is not equal to true
The false branch of your Condition will be all iterations where the item is a folder and should have this structure:
items('Apply_to_each')?['{FullPath}']
last(split(outputs('FullFolderPath'), variables('strTemplateLibraryName')))
<the URL of the site you are copying files to>
<the document library you are copying files to>
outputs('FolderPath')
The true branch of your Condition will be all iterations where the item is a file and should have this structure:
items('Apply_to_each')?['{FullPath}']
first(split(last(split(outputs('FullFilePath'), variables('strTemplateLibraryName'))),item()?['{FilenameWithExtension}']))
<the URL of the site you are copying files to>
items('Apply_to_each')?['{Identifier}']
<the URL of the site you are copying files to>
/variables('strTargetLibraryName')outputs('FilePath')
items('Apply_to_each')?['{FilenameWithExtension}']
body('Get_file_content')
When I made this flow a while back, I was referencing this guide that you might find helpful. It is difficult to write out flows on here so please let me know if you have any questions.
Upvotes: 0