Flow / Power Automate - SharePoint: Automate File Movement to an Archive Library Tutorial

Learn to automate file movement in a SharePoint archive library using variables, conditional elements, and Power FX functions. Imagine maintaining source folder structure in the target library. Set up a recurring flow to retrieve and process files, and recreate the original structure in the archive library. This tutorial provides a comprehensive guide for efficient archiving between SharePoint libraries!

  • 05:20
  • 29 views

Objectifs :

This tutorial aims to teach you how to automate the movement of files in a SharePoint archive library, taking into account various constraints. You will learn to use variables, conditional elements, and Power FX functions to create a recurring flow that organizes files based on their age while maintaining the original folder structure.


Chapitres :

  1. Introduction to File Automation
    Welcome to this tutorial where you will learn to automate the movement of files in an archive library. This process involves a more complex flow that must consider a series of constraints.
  2. Understanding the Task
    In this video, you will use variables, conditional elements, and Power FX functions. Imagine needing to move files from a folder in a SharePoint library based on their age. The goal is to move these files while maintaining the source folder and file structure, ensuring an identical organization of your content in the target library, which is your archive library.
  3. Setting Up Your SharePoint Libraries
    In this SharePoint site, you will find a standard library named 'Documents' containing a folder titled 'Files to Move.' This folder has a series of files of varying ages. Optionally, you can add a column for the file creation or modification date, which isn’t shown by default. Your second library, named 'Archives,' is currently empty and will need to be automatically populated.
  4. Creating a Recurring Flow
    To begin, you will initiate a recurring flow that runs on the first of each month at 6 a.m. The first action will be to retrieve files from the folder containing potential files to be moved. While you could process the entire contents of your document library, this tutorial will focus on a specific folder.
  5. Configuring Advanced Settings
    Enable advanced settings to apply a query that limits the flow to the chosen folder, including files in the subfolders. Enter the parameters related to nested items and specify the folder to be processed. In this example, you will only move files created two years ago or more.
  6. Setting Filter Criteria
    The filter query will specify this criterion. Enter the name of the created column for the file creation date. You can also use 'modified' for the date of the last modification of the file. Set your criterion to 'le' (less than or equal) and enter an apostrophe to reference your deadline relative to the file creation date.
  7. Using Power FX Functions
    Use the Power FX button to enter a formula that references the current date (UTC now) associated with the 'A day' function, defining minus 730 days (about two years). This will allow you to subtract 730 days from the current date.
  8. Processing Files
    When SharePoint lists the files, it will include the names of the subfolders. To recreate the original structure in your archive library, constrain this action by adding a query parameter that excludes folder-type objects from the result. Initialize a text variable named 'folder' and populate it during future processing.
  9. Looping Through Files
    Files dated over two years will be listed. Begin their processing by initializing an 'Apply to Each' loop that retrieves the dynamic content body value, which is the list of items to process. Within the loop, populate your 'folder' variable by retrieving the access path of each file.
  10. Managing File Paths
    Choose the action related to variables to set your 'folder' variable. The access path of the file to be moved will contain the name of the library 'Shared Documents' and the subfolder 'Files to Move.' Use a Power FX formula to replace this path with empty space in your variable to retrieve only the relative path inside the folder to be processed.
  11. Handling Folder Structure
    The last character of your 'folder' variable will contain a slash, which will cause an issue when moving the file to be archived. Use the 'slice' function to retrieve the path string from position index zero to index minus one, corresponding to the slash to be removed. If the file is at the root of your 'Files to Move' folder, the variable will contain empty space; otherwise, it will contain the path of the folder where the file is placed.
  12. Creating Folders in SharePoint
    Manage an 'if' condition to test if the 'folder' variable is empty. If so, add the SharePoint action to create folders in your SharePoint site within your archives library, using the relative path of the folder corresponding to the file being processed.
  13. Moving Files to Archive
    After creating or not creating the folder, still within the loop, add the action to move the processed file. Refer to the file to be moved by its complete original path and set the destination folder corresponding to your archives library, followed by the path stored in your variable. If another file already exists, choose to replace it.
  14. Conclusion
    Finally, save and test your flow. Files over two years old will be moved to the root of your archives library, and for files stored in subfolders, the original structure will be recreated. This is how to create a complete archiving flow between SharePoint libraries.

FAQ :

What is the purpose of automating file movement in SharePoint?

Automating file movement in SharePoint helps maintain organization, ensures timely archiving of old files, and reduces manual effort in managing file storage.

How do I set up a recurring flow in Power Automate?

To set up a recurring flow in Power Automate, you can use the 'Recurrence' trigger, specify the frequency (e.g., monthly), and set the time for the flow to run.

What are Power FX functions?

Power FX functions are formulas used in Microsoft Power Platform to perform calculations, manipulate data, and automate tasks within applications.

How can I filter files based on their creation date in SharePoint?

You can filter files based on their creation date by using a filter query in your flow that specifies the date criteria, such as files created two years ago or more.

What should I do if a file already exists in the destination folder?

If a file already exists in the destination folder, you can choose to replace it during the file movement process in your flow.


Quelques cas d'usages :

Automating Document Archiving

In a corporate environment, a company can automate the archiving of old project files from a SharePoint library to an archive library. By setting up a flow that runs monthly, the company ensures that all files older than two years are moved, maintaining the original folder structure, which helps in easy retrieval of archived documents.

Managing Compliance Records

A legal firm can use this automated flow to manage compliance records by moving files that are no longer active to an archive library. This helps in keeping the active library clutter-free while ensuring that all compliance documents are stored securely and can be accessed if needed.

Streamlining File Organization

An educational institution can implement this flow to regularly archive student records and course materials that are no longer in use. By automating the process, the institution can ensure that their document library remains organized and that important historical data is preserved in an accessible manner.


Glossaire :

SharePoint

A web-based collaboration platform developed by Microsoft that integrates with Microsoft Office. It is used for storing, organizing, sharing, and accessing information from any device.

Power FX

A low-code programming language used in Microsoft Power Platform to create custom business logic and automate processes.

Flow

A feature in Microsoft Power Automate that allows users to automate workflows between applications and services.

UTC

Coordinated Universal Time, a time standard that is the basis for civil timekeeping worldwide.

Variable

A storage location identified by a name that can hold data which may change during the execution of a program.

Loop

A programming construct that repeats a block of code as long as a specified condition is true.

If Condition

A conditional statement that executes a block of code if a specified condition is true.

Folder Structure

The organization of folders and subfolders within a file system, which helps in managing and locating files.

Filter Query

A set of criteria used to limit the data retrieved from a database or service based on specific conditions.

00:00:05
automate the movement of files in an archive library.
00:00:09
This more complex flow will have to take into account a series of constraints.
00:00:14
In this video, you will use variables, conditional elements and power FX functions
00:00:21
to start
00:00:22
imagine that you need to move files from a folder in a sharepoint library.
00:00:26
Depending on the age of the files,
00:00:28
you will need to move them while maintaining the source folder and file structure
00:00:32
to keep an identical organization of your content in the target library.
00:00:36
That is your archive library. In
00:00:39
this sharepoint site,
00:00:40
you will find a standard library named documents in
00:00:43
which there is a folder titled files to move
00:00:47
this folder contains a series of files of varying ages.
00:00:51
You can optionally add a column for the file
00:00:53
creation or modification date which isn't shown by default.
00:00:58
Your second library named archives is currently completely
00:01:02
empty and will need to be automatically populated
00:01:06
to begin.
00:01:07
You will initiate a recurring flow that will run on the first of each month at 6 a.m.
00:01:19
The first action will be to retrieve
00:01:21
the files from the folder containing the potential
00:01:23
files to be moved while you could process
00:01:26
the entire contents of your document library.
00:01:28
In this tutorial, we will limit ourselves voluntarily to a specific folder.
00:01:34
Enable advanced settings to apply a query that will limit the flow to the
00:01:37
chosen folder while including the files in the sub folders of the targeted folder.
00:01:43
Then enter the parameters related to nested items
00:01:46
and specify the folder to be processed.
00:01:48
In
00:01:49
this example, we will only move files created two years ago or more.
00:01:54
The filter query will specify this criterion.
00:01:57
Enter the name of the created column for the file creation date.
00:02:01
You can also use modified for the date of last modification of the file.
00:02:06
Then set your criterion to le meaning less or equal.
00:02:11
You will then enter an apostrophe to reference
00:02:13
your deadline relative to the file creation date.
00:02:17
Use the power FX button and enter the
00:02:20
following formula which allows referencing the current date UTC
00:02:24
now associated with the A day function by defining minus 730 days or about two years.
00:02:32
Concretely. In this example, you will subtract 730 days from the current date.
00:02:39
When SharePoint lists the files, it will include the names of the sub folders.
00:02:43
In the result,
00:02:44
you will need to constrain this action by adding
00:02:46
a query parameter excluding folder type objects from the result
00:02:52
to recreate the original structure in your archive library, initialize a text,
00:02:57
variable named folder and populate it during future processing
00:03:02
the files dated over two years are listed,
00:03:05
begin their processing by initializing a apply to each
00:03:08
loop that will retrieve the dynamic content body value,
00:03:12
which is the list of items to process.
00:03:15
Always within the loop. Populate your folder.
00:03:18
Variable by retrieving the access path of each file.
00:03:21
Choose the action related to variables to set your folder. Variable.
00:03:27
Note several technical elements here,
00:03:30
the access path of the file to be moved
00:03:32
will contain the name of the library shared documents
00:03:35
as well as the sub folder files to move,
00:03:39
use a power FX formula to replace this path with empty space in your
00:03:43
variable to retrieve only the relative path inside the folder to be processed.
00:03:51
Another important point,
00:03:52
the last character of your folder variable will contain a slash which
00:03:57
will cause an issue when moving the file to be archived.
00:04:00
Use the slice function to retrieve the path string from position index
00:04:04
zero to index minus one corresponding to the slash to be removed.
00:04:10
If the file is at the root of your files to move folder,
00:04:13
the variable will contain empty space.
00:04:16
Otherwise it will contain the path of the folder where the file is placed.
00:04:21
Manage an if condition testing if the folder variable is empty.
00:04:27
If so add the SharePoint action to create folders to
00:04:31
create in your SharePoint site within your archives library.
00:04:35
The relative path of the folder corresponding to the file being processed
00:04:41
after creating or not the folder still within the loop.
00:04:44
Add the action to move the processed file,
00:04:46
refer to the file to be moved by its complete original path and set the
00:04:50
destination folder corresponding to your archives library followed
00:04:55
by the path stored in your variable.
00:04:57
If another file already exists, choose to replace it,
00:05:01
finally save and test
00:05:05
files over two years old will be moved to the root of your archives library
00:05:09
for files stored in sub folders. The original structure will be recreated.
00:05:14
This is how to create a complete archiving flow between sharepoint libraries.

No elements match your search in this video....
Do another search or back to content !

 

Mandarine AI: CE QUI POURRAIT VOUS INTÉRESSER

Reminder

Show