How to delete older files in each folder

Zaeemul Haque 20 Reputation points
2024-01-19T02:39:24.54+00:00

Hello, I am trying to delete older files from each folder. for example --- I have Root directory /FOLDERA/NAMES/ names_1/1/2024.csv names_1/2/2024.csv names_1/3/2024.csv names_1/4/2024.csv

/FOLDERA/ADDRESS/ address_1/1/2024.csv address_1/2/2024.csv address_1/3/2024.csv address_1/4/2024.csv /FOLDERA/EMPLOYEE/ employee_1/1/2024.csv employee_1/2/2024.csv employee_1/3/2024.csv employee_1/4/2024.csv I need to delete two weeks older files in each folder, how can be achived. I saw the example mostly deleting files in one folder or directory, Please let me know if any example or screeshot or document to delete old files in each folder. Thank You, Zaeemul

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,942 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,637 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Nandan Hegde 31,511 Reputation points MVP
    2024-01-19T09:31:41.16+00:00

    Hey, You can use Delete activity: User's image

    wherein you can use wild card path and last modified combination to pick files less that specific date and delete the files recursively. You can also use life cycle management property in case if blob is the source : https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-policy-configure?tabs=azure-portal

    0 comments No comments

  2. KarishmaTiwari-MSFT 18,957 Reputation points Microsoft Employee
    2024-02-06T00:33:41.1966667+00:00

    @Zaeemul Haque To delete older files from each folder in Azure Blob Storage, you have a couple of options:

    #1. Blob Lifecycle Management (Recommended): Azure Storage provides a feature called Blob Lifecycle Management. With this, you can define policies to automatically delete blobs based on criteria such as their age (e.g., older than 30 days). Go to your Azure Storage Account.Navigate to Blob Service > Lifecycle Management. Define a policy to delete blobs older than your desired threshold (e.g., 14 days). Azure Storage will handle the deletion for you.

    #2. Azure Functions: You can create an Azure Function that periodically checks each folder and deletes files older than a specified duration. Here’s a high-level approach: Create a Timer Trigger function. Fetch the list of blobs from the corresponding Blob Container. Check the LastModified property of each blob. Delete the blobs that don’t meet your criteria (e.g., older than 14 days).

    Remember to test any deletion process on a test folder first to avoid accidental data loss. Adjust the path and days as needed for each folder.