【问题标题】:How to check if multiple files exists in azure container如何检查Azure容器中是否存在多个文件
【发布时间】:2019-07-19 15:46:34
【问题描述】:

要检查 azure 容器中是否存在单个 blob,我们有以下解决方案,

public bool DoesFileExistsInContainer(string fileName, string containerName)
    {
        try
        {
            if (fileName == null)
            {
                throw new ArgumentException("File name to be moved is empty");
            }
            CloudBlobContainer containerReference = blobClient.GetContainerReference(containerName);
            CloudBlockBlob blob = containerReference.GetBlockBlobReference(fileName);

            bool isFileExist = blob.Exists();                
            return isFileExist;
        }
        catch (StorageException ex)
        {
            Logger.LogError("error while checking if blob exists : {0}" + ex);
            throw;
        }
    }

但我想检查 azure 容器中是否存在多个文件?

string[] filesToSearchInBlob = {"file1.xml", "file2.xml", "file3.xml"};

除了在 foreach 循环中之外,还有其他有效的检查方法吗? 使用 LINQ?我们能以更好的方式做到这一点吗?

提前致谢

维努

【问题讨论】:

    标签: azure-storage exists not-exists


    【解决方案1】:

    我认为没有比foreach 循环更有效的方法了。如果您确实认为性能是一个问题,您可以考虑同时调用Exists 方法。

    【讨论】:

    • 如果 blob 的数量很少,您还可以检索所有 blob 的列表并在其上运行循环。这可能比通过互联网拨打多个电话更有效。
    • 谢谢.. 由于 blob 会随着时间的推移而增长,我会采用 Exists 方法。
    猜你喜欢
    • 1970-01-01
    • 2022-11-04
    • 2020-07-22
    • 2014-06-06
    • 2012-06-17
    • 2011-10-14
    • 2016-03-19
    • 2021-05-16
    • 2022-12-06
    相关资源
    最近更新 更多