How to move a file on Azure File Storage from one sub folder to another sub folder using the Azure Storage SDK?

时光怂恿深爱的人放手 提交于 2019-12-10 12:59:20

问题


I'm trying to figure out how to move a file in Azure File Storage from one location to another location, in the same share.

E.g.

source -> \\Share1\someFile.txt
destination -> \\Share1\Foo\Bar\someFile.txt
  • Do I need to copy the file first, then delete the source?
  • What if the destination sub-directory aren't there? do I need to CreateIfNotExistsAsync for each sub-directory, first?

cheers!


回答1:


This is documented in the Getting Started guide on Azure Storage Files reference.

What you need is the StartCopy method to copy the file from one location to another.

// Start the copy operation.
destinationFile.StartCopy(sourceFile);

And, yes, you will have to create the destination directory if it does not exist.




回答2:


Unfortunately we don't have move / rename functionality exposed through the REST API that the Client SDK's are dependent on. You can of course perform these functions via SMB. We do have these features on our backlog but don't have a timeline yet for implementation.




回答3:


Like this:

public static void MoveTo(this CloudFile source, CloudFileDirectory directory)
{
    var target = directory.GetFileReference(source.Name);
    target.StartCopy(source);
    source.Delete();
}



回答4:


An Azure Storage File share is an SMB-compatible share. So you should be able to make file copies/moves with normal file I/O operations. This is in contrast to direct blob manipulation, where you need to specifically create containers, initiate blob copies, etc. via the Storage API.




回答5:


Azure blob sub directors are a virtual feature in that they don't physically exist, the name of the blob/file contains the full path. Because of that you don't have to explicitly "create" the directory.

I don't think that an atomic "rename" method exists for Azure blobs/files... To get around it you would have to copy (with the new name) and then delete the original.



来源:https://stackoverflow.com/questions/39575130/how-to-move-a-file-on-azure-file-storage-from-one-sub-folder-to-another-sub-fold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!