Search code examples
pythonazureazure-blob-storageazure-storage

How to fetch last modified dates of ADLS Gen2 files and save it to a csv in python


I am very new to work with Azure. I need help to fetch the last modified dates from a specific ADLS location and save those information in another container as csv file.

I have my input path as string type.

path='teams\test\A.json'

blob.properties.last_modified(path)

But it's not working. Kindly help me how can I solve this issue if my file input path is in string format?


Solution

  • Your question mentions ADLS gen2 but in your code sample you are referring to a file in the C drive. You also need to specify the SAS token of the ADLS Gen 2 blob whose properties you are trying to fetch.

    What you will require is the Blobclient. Have a look at the documentation.

    Install the required python lib.

    pip install azure-storage-blob
    

    The python code will look like this.

    from azure.storage.blob import BlobClient
    sasurl = "xxxxxxx"
    blob_client = BlobClient.from_blob_url(sasurl)
    print(blob_client.get_blob_properties().last_modified)