Reputation: 11
I have created code to getting the files list from the Azure blob container.
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = new ContainerClient(
`https://${account}.blob.core.windows.net/${containerName}`,
sharedKeyCredential
);
console.log("Listing all blobs");
i = 1;
for await (const blob of containerClient.listBlobsFlat()) {
console.log(`Blob ${i++}: ${blob.name}`);
}
above code return list of all files. but in my container, there are two folders one is IN folder and the second is OUT folder. I just need only the files list from IN folder.
is that any function available to get a list from a specific directory?
Upvotes: 1
Views: 2241
Reputation: 136196
Just add prefix
option in your listBlobsFlat
method and you will be able to list blobs from IN
folder only. Something like:
for await (const blob of containerClient.listBlobsFlat({prefix: 'IN/'})) {
console.log(`Blob ${i++}: ${blob.name}`);
}
You can learn more about blob listing options here: https://learn.microsoft.com/en-us/javascript/api/@azure/storage-blob/containerlistblobsoptions?view=azure-node-latest
Upvotes: 3