0

I have a condition wherein, my document library has year wise folders, within each of these folders are several document sets and each of them hold few files/documents. I am looking to build a Flow that can archive and delete the files & document sets which have not been modified for over 6 months. Help would be appreciated.

  • In your Archive library, do you want to create the same types of structure of folders/document sets that you have in the current library? Or just copying the files to the Archive library is good enough? Maintaining the same structure in the Archive will create complexity in the Flow – Matiur Rahman Oct 15 '20 at 16:49
  • yes please, I would like to maintain the same structure. I referred many posts but couldn't get an exact solution. – Sanjana V Oct 19 '20 at 17:39
0

Here are the steps of a basic MS Flow that can be used to archive files from one Document Library having folders/document sets to another Library. Of course, it can be enhanced to suit your needs.

Concept of the MS Flow

  1. SharePoint - Source Document Library contains folders and document sets and the destination Document Library contains the meta data fields, same as the source, but doesn't have any folders

  2. Get all files' properties with a Filter Query as shown below.

Created le 'addDays(utcnow('yyyy-MM-ddTHH:mm:ssZ'),-180)'

  1. Add a [Compose] action and run the flow to see if the desired files/folders properties are retrieved with the query. The output from the [Compose] action is to be used to generate schema for [Parse JSON], the next action step

  2. Add [Parse JSON] with a schema built from the output data in step 3. This step is helpful to select file properties from the dynamic content window and use in the subsequent steps

  3. Process each items with a [Apply to each] action. Within it, check if the item is a folder or file. If it's a file, transfer to the Archive Library and delete it from the source.

Screenshots showing the details

enter image description here

Detail 1

enter image description here



Updating my previous response to include steps to create Folders and Document Sets in the Archive Library based on the structure in the Source Library

Please see the screenshots and explanation below

enter image description here

enter image description here

Detail Apply to Each 2

enter image description here

Detail Condition 2

enter image description here

Detail Copy File

enter image description here

Few Expressions shown on the screenshots

For TempFilePath:
substring(string(items('Apply_to_each_2')['{Path}']), 0, sub(length(string(items('Apply_to_each_2')['{Path}'])),1))

For TempSlug:
concat(variables('WebUrl'),'/', replace(variables('TempFullPath'),variables('SourceLibraryName'),variables('ArchiveLibraryName')), '|', variables('ArchiveCTypeIDGUID'))

For Get folder metadata Folder Path:
replace(variables('TempFullPath'),variables('SourceLibraryName'),variables('ArchiveLibraryName'))

Create new folder Folder Path:
replace(variables('TempFullPath'), concat(variables('SourceLibraryName'), '/'),'')

For ArchiveFilePath:
concat('/',replace(variables('TempPath'), variables('SourceLibraryName'),variables('ArchiveLibraryName')))

  • Hi @Matiur Rahman, Thank you. This worked for me to copy only the files within a document set from Library A to Library B. The Structure of Library A is Year wise Folders -> Document Sets -> files. Each year folder on Library A has several document sets, likewise every document set consists of many files. So the requirement i am looking for is to have same structure maintained on my destination library B. As of now I am able to only copy the files directly into Library B, without having its parental structure. Could you give some more help on this. – Sanjana V Oct 19 '20 at 17:37
  • That's little complicated, but I think doable. I will try to provide some guidelines later today. – Matiur Rahman Oct 19 '20 at 18:05
  • Could you provide some detail of the structure of your library? Would like to know hierarchy as to how documents are located inside the library like: DocLibrary/DocZeroOne.docx; DocLibrary/Folder1/DocOne.docx; DocLibrary/Folder1/DocSet1/DocTwo.docx etc – Matiur Rahman Oct 20 '20 at 13:09
  • Structure is DocLibrary/YearFolder/DocumentSet/File.png; Example: DocLibrary/2020/A_123_ABC/ProfilePic.png – Sanjana V Oct 20 '20 at 14:58
  • It took a while to complete the solution. Let me know if you have any questions or need clarification – Matiur Rahman Oct 21 '20 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.