I have an Azure logic app that's getting blob contents from my Azure storage account on a regular basis. However, my blobs are getting stored in sub-directories. Eg. MyContainer > Invoice > 20200101 > Invoice1.csv
Every month my 3rd sub-directory that is '20200101' will change to '20200201', '20200301' so & so forth. I need my Logic app to return the blob contents of the latest folder that gets created in my container. Any advice regarding this?
Thanks!!
For this requirement, please refer to my logic app below:
1. List all of the folders under /mycontainer/Invoice/
.
2. Initialize two variables in type of Integer, one named maxNum
and the other named numberFormatOfName
.
3. Use "For each" to loop the value
from "List blobs" above. In "For each" loop, first set numberFormatOfName
with expression int(replace(items('For_each')?['Name'], '/', ''))
. Then add a "If" condition to judge if numberFormatOfName
greater than maxNum
. If true, set the value of maxNum
with numberFormatOfName
.
4. After the "For each" loop, use another "List blobs" to list all of the blobs in latest(max number) folder. The expression in below screenshot is string(variables('maxNum'))
.
If you do not want list blobs, but you want get the blob content. You can do it like below:
==============================Update==============================
Running the logic app, I get the result shown as below screenshot:
I created three folders 20200101
, 20200202
, 20200303
under /mycontainer/Invoice
in my blob storage. The content of three csv file are 111,111
, 222,222
, 333,333
. The logic app response the third csv file content 333,333
.
=============================Update 2=============================