I am a newbie to c# and .net and Azure developement i wanna copy all files from a directory and move the copy of those file to different directory in same azure blob container so that i can work with the copy of file when the original file is safe. But had no idea how to do so..
I have tested in my environment
You can use the below code to copy blobs from one directory to another directory in a same container in Azure Blob Storage:
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
var connectionString = "StorageAccountConnectionString";
string containerName = "ContainerName";
string directory1 = "SourceDirectory";
string directory2 = "TargetDirectory";
var serviceClient = new BlobServiceClient(connectionString);
var containerClient = serviceClient.GetBlobContainerClient(containerName);
foreach (BlobItem blob in containerClient.GetBlobs())
{
if (blob.Name.Contains(directory1))
{
var blobUri = containerClient.GetBlobClient(blob.Name);
var newBlob = containerClient.GetBlobClient(blob.Name.Replace(directory1,directory2));
newBlob.StartCopyFromUri(blobUri.Uri);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.