Pattern search in Azure blob file names

Viewed 8282

I am trying to search files that match my search pattern.

static void ListBlobsInFolder() {
            var account = <MyStorageAccount>
            var blobClient = account.CreateCloudBlobClient();
            var containerName = "importcontainer";
            var folderName = "subfolder";
            var container = blobClient.GetContainerReference(containerName);
            var query = container.ListBlobs(prefix: folderName, useFlatBlobListing: true, blobListingDetails: BlobListingDetails.None);
            foreach(var item in query) {
                Console.WriteLine(item.Uri.Segments.Last());
            }
        }

This gets me the list of files present in the subfolder.

Is there a way to return the files that only match a pattern. Example I want to retrieve file names that contains "abc" in it.

Is this possible in Azure ?

1 Answers

Is there a way to return the files that only match a pattern. Example I want to retrieve file names that contains "abc" in it.

Unfortunately it is not possible. There's limited support for server-side searching in Azure Blob Storage. Only thing you can filter on is the blob prefix i.e. you can instruct Azure Storage service to only returns blobs names of which start with certain characters.

For your scenario, you will need to fetch the list of all blobs in a blob container and do the filtering on the client side.

Related