Bạn có thể nhận được một danh sách các đốm màu trong một container với CloudBlobContainer.ListBlobs() hoặc bên trong một thư mục với CloudBlobDirectory.ListBlobs()
CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));
//Get a reference to the container.
CloudBlobContainer container = blobClient.GetContainerReference("container");
//List blobs and directories in this container
var blobs = container.ListBlobs();
foreach (var blobItem in blobs)
{
Console.WriteLine(blobItem.Uri);
}
Bạn sẽ cần phải phân tích các tên tập tin từ blobItem.Uri, nhưng sau đó bạn có thể sử dụng LINQ của Trừ() phương pháp để tìm ra sự khác biệt:
public string FindFilesToDelete(IEnumerable<string> fromAzure, IEnumerable<string> yourList)
{
return fromAzure.Except(yourList);
}
đó sẽ trở lại tất cả mọi thứ trong danh sách fromAzure đó không phải là trong yourList.
Và cuối cùng bạn có thể xóa các đốm màu với this example
Tôi có cấu trúc chứa này/folder1/folder2/folder3/myfile.txt. Container.ListBlobs chỉ trả về tối đa thư mục1. Có cách nào để lấy tất cả các tệp, nói trong thư mục3 không? –