How to list files and folders metadata in azure file storage with logic app workflow?

amerm 0 Reputation points
2025-01-13T19:52:46.47+00:00

Hello,

Could you please help me with this?

I'm trying to build an azure logic app for a storage account. Inside this storage account there are like 20 azure files. In each azure file share there are several files and folders. I want to create a workflow that would would check each file's last modified where I want it to move files and folders that are older than 120 days to a different storage account.

I want to know:

  1. how to list each azure file in the in the storage account.
  2. How to loop between each azure file and its contents to get files and folders that are older than 120 days.
  3. How do I list the results retaining each file/folder's path in a text file for example to have like local report stored somewhere?
  4. what I would do if I needed to limit the scope of this to a certain folder in an Azure file.
Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,341 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,303 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 15,086 Reputation points
    2025-01-14T12:24:18.41+00:00

    Hello amerm,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to create a workflow that would check each file's last modified where I want it to move files and folders that are older than 120 days to a different storage account.

    Your Logic App workflow should be similar to the followings:

    1. Trigger: Recurrence
    2. Action: Initialize Variables
    3. Action: List Files in Folder
    4. Control: For Each (loop through files)
       - Action: Get File Metadata
       - Condition: If file is older than 120 days
         - True:
           - Copy File
           - Delete File
           - Append File Path to Variable
    5. Action: Create File (Report)
    6. Optional: Recursive Call for Nested Folders
    

    Regarding your questions:

    1. how to list each azure file in the in the storage account?

    To list files and folders in an Azure File Storage, you can use the Azure File Storage connector in Logic Apps. Here’s how you can set it up:

    • Create a Logic App in the Azure portal.
    • Add a new step and search for the Azure File Storage connector.
    • Choose the "List files in folder" action**. You will need to provide the path to the folder you want to list.
    1. How to loop between each azure file and its contents to get files and folders that are older than 120 days?

    To loop through each file and folder, you can use the "For each" control in Logic Apps:

    • After listing the files, add a "For each" control.
    • Set the output of the "List files in folder" action as the input for the "For each" control.
    • Inside the "For each" loop, you can add actions to get the metadata of each file, such as the last modified date.

    To check the last modified date and move files older than 120 days:

    • Inside the "For each" loop, add a condition to check if the file's last modified date is older than 120 days.
    • If the condition is true, add an action to move the file to a different storage account. You can use the "Copy file" and "Delete file" actions to achieve this.
    1. How do I list the results retaining each file/folder's path in a text file for example to have like local report stored somewhere?

    To list the results and retain each file/folder's path:

    • Inside the "For each" loop, add an action to append the file path to a variable.
    • After the loop, add an action to create a file in a storage account or send an email with the list of file paths.
    1. what I would do if I needed to limit the scope of this to a certain folder in an Azure file?

    To limit the scope to a certain folder, you can specify the folder path in the "List files in folder" action. This way, the Logic App will only process files and folders within the specified path.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.