azureazure-functionsazure-function-appazure-functions-runtimeazure-function-async

how to create a sub folder in azure storage account and copy the files by using azure function App


I have two folders in my storage account Source and destination folders I want to add Demo folder in my Source folder and I want to copy my source folder files to Demo folder and delete all my source folder files after copying in to Archieve folder

  1. how to create a folder inside another folder
  2. how to copy files from one folder to another folder

how to add a folder I am passing in this way:

 var directory2 = container.GetDirectoryReference("csvfile / Source Folder / Archieve Folder");
        CloudBlockBlob blockBlob2 = directory2.GetBlockBlobReference("empchange1.csv");
  1. containername-csvfile
  2. Folder-Source
  3. SubFolder-Archieve

Solution

  • There is no such thing as a (physical) folder in Azure Blob Storage. There is only the concept of virtual folders. By using a / in the name you are creating a virtual folder. For example, a blob named virtualfolder/myblob.ext is placed in a virtual folder named virtualfolder.

    If you want to create a virtual subfolder just put the name in the blob and use the '/' as delimiter like this:

    virtualfolder/subfolder/myblob.ext

    The notion of virtual folders is mentioned also if you take a look at the docs for cloudblobdirectory

    Represents a virtual directory of blobs, designated by a delimiter character.

    That said, moving a blob to a different folder would therefore the same as renaming a blob to, for example otherfolder/myblob.ext. Unfortunately there is no API that allows you to rename a blob. The solution is to download the blob contents and upload it with a different name.