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,343 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,313 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sina Salam 15,396 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.


  2. Nandamuri Pranay Teja 325 Reputation points Microsoft Vendor
    2025-01-15T09:13:42.9033333+00:00

    Hello amerm

    Welcome to Microsoft Q&A Forum. Thanks for posting your query here!

    In additional to above response provided by Sina Salam I would also suggest you to follow the below steps.

    • In the Azure portal, create a new Logic App and Choose the "Blank Logic App" template.
    • In the designer, search for "Recurrence" and add it as the first step and configure the recurrence schedule (e.g., daily, weekly) based on how often you want to check for old files.
    • Add an "Azure File Storage" action, select ''List file shares" as the operation and configure the connection to your source storage account. This will return a list of all file shares within that storage account.

    Regarding the Last Modified Date

    • Add a "Filter array" action and configure the filter expression to select files where the "Last Modified" property is older than 120 days.
    • Expression: @and(greater(utcNow('yyyy-MM-ddTHH:mm:ssZ'), addDays(items('For_each')?['properties']['last_modified'], 120)))
    • This expression checks if the current UTC time is greater than the "Last Modified" time of the file plus 120 days.

    Post which Loop Through Filtered Files and Add another "For each" loop to iterate through the filtered list of files. Inside this loop, add an "Azure File Storage" action-Select "Create file" as the operation-Configure the connection to your destination storage account-Set the "File Path" in the destination storage account dynamically

    Example: @{concat(variables('destinationFileShareName'), '/', items('For_each')?['name'])}

    Replace variables('destinationFileShareName') with the name of the destination file share (you can define this as a variable if needed). And set the "File Content" to the content of the source file. You can use the "Get file content" action before this step.

    Please be informed that for large numbers of files, consider optimizing the workflow for performance (e.g., by using parallel processing, batching file operations). Monitor the Logic App runs for any errors or issues. Thoroughly test your Logic App with a small set of files before running it on a larger scale.

    Note-Implement error handling using "Scope" and "Retry" actions to gracefully handle potential issues during the file transfer process.

    Let us know if you have any questions or concerns, we are here at your service!

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. which might be beneficial to other community members reading this thread. 

    User's image

    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.