This example will show a case where I want to run a reoccurring flow to go through a document library and any folder marked for Archiving it will move it and all files in the directory into a new document library

If you want to preserve the created date, created by, modified date, and modified by fields then on the archive document library create fields for that information. I created the following columns on the Archive document library

  • oCreated (Date)
  • oCreatedBy (People Picker)
  • oModified (Date)
  • oModifiedBy (People Picker)
  • Product (Choice: Choice 1/Choice 2/Choice 3)
  • Cost (Number)

on the Source document library I created the following columns

  • Archive (Choice: Yes/No)
    • I chose NOT to use the yes/no column type because I could not get the boolean to filter proper for some reason
  • Product (Choice: Choice 1/Choice 2/Choice 3)
  • Cost (Number)

Below is my example Source Document library

On the far right you will notice I have the following folder and nested folders marked for Archiving

  • Something1
  • Something2/test
  • Something2/TwoDeep/ThreeDeep

Here is a quick look at the flow and I will break it down if you keep scrolling (This will only work for Folders. I don’t have any checks for files marked Yes on Archive so it will fail for files)

Create a new flow and select the trigger you are needing (I won’t go over this part. I selected a Scheduled Flow)

I have created 4 Initialize Variable Actions like so

Next I will get the properties of ANY item marked for archiving equal to yes

  • Library name: Is the name of my original source document library
  • Filter Query: This is the name of the column to filter by
  • Order By: I did this to order all the files ascending by their folder name

Now I create an Apply to Each action and add the value from the above


Inside the apply to each I created each of the following actions

Compose CreateArray from FullPath

@{split(items('Apply_to_each_FolderPath')?['{FullPath}'], '/')}

Condition to Handle Nested Folders


Compose Remove First and Last Folder

@{take(skip(outputs('Compose_CreateArray_from_FullPath'), 1), add(length(outputs('Compose_CreateArray_from_FullPath')), -2))}

Next I created the following actions



Set variable TruncatedFolder


Create new folder


Get folder metadata using path


Get file properties


Next create and Update file properties action





You will repeat the steps for any other columns needing to match on the new folder


The next step is copy folder (you may be able to use move folder to avoid any delete cleanup steps at the end of the flow)

Folder to Copy


Destination Folder


Add an Update File Properties action





oCreatedBy Claims




oModifiedBy Claims


Create a Get files (properties only) action for Archive Test

Limit Entries to Folder


In the below pic I forgot to include the Order By field under advanced options

Order By

FileLeafRef asc

I will then create the same action but for Source Test

Limit Entries to Folder


Order By

FileLeafRef asc

Next I created a Select Action with the following Map



The map info is the same as above for oCreated, oCreatedBy, oModified, oModifiedBy

Create a set variable action to set ColumnPropertiesArray


Create a new Apply to each action and put a Compose and Parse JSON action inside with the following expressions and output

Select an output from previous steps


Compose FirstIndex of CoumnPropertiesArray



Parse JSON




    "type": "object",
    "properties": {
        "oCreated": {
            "type": "string"
        "oCreatedBy": {
            "type": "string"
        "oModified": {
            "type": "string"
        "oModifiedBy": {
            "type": "string"

Create an Update file properties for ArchiveTest





oCreatedBy Claims




oModifiedBy Claims


For the last three steps I created an Increment variable, Compose, and Set variable action

Increment variable Counter



Compose Skip to the Next ColumnPropertiesArray Index


@{skip(variables('ColumnPropertiesArray'), 1)}

Set variable Column PropertiesArray NextIndex



This flow as is won’t delete the Source folder so if you want that done steps will need added that I am not going to cover at this time or you can scroll up and on the copy folder action a move folder action should work

Also this current flow will preserve the Created, CreatedBy, Modified, and ModifiedBy values to the new archive columns created so if you don’t need that requirement the final Apply to each can be removed

This was a long post but I hope it helps someone and is not too confusing