开发者

Getting Last Azure Blob in the container

I have a list of blobs with the following names in my container

eg. item1 item2 item3 item9 item10 item12 item45

I want to get the first and last blob, which in this case is item1 and item45

However when i use cloudblobclient.cloudblobdirectory.listblobs.last, item9 was returned to me, not what I wanted. What would be the best way to get the last item (45) from the list.

Can only think of running through the full list, then for each item, get the number after the characters "item" and compare that number to previous high or low. Since the first 4 characters are fixed, I will combine the "item" and higherCnt:

for each blobitem in listblobs
  iCurrCnt = numeric(blobitem.uri.absolutepath.substring(4)) 
  if iCurrCnt > iHigherCnt then
 开发者_开发技巧 iHigherCnt = iCurrCnt 

thus the blob that was the last (item45):

strHighestCntFileName = "item" + iHigherCnt

Is there an alternate way to do this? Worries about performance when the item list grows to thousands. I am only interested in the first and last blob. Thanks!


I think there are following ways you can achieve this thing:

  • Get the list of all blob existing in container and then filer blob which you want.

  • Use blob prefix when listing blobs existing in container. So if you have an idea of 1st and last blob name then you can use it in blob prefix, which will return you the list of blobs matching specified blob prefix.

Hope this helps.

Regards, Amit jain www.cerebrata.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜