Srikant Krishna on Sat, 10 Sep 2016 23:11:49

I use Azure Storage, the File Service, and the Python SDK.

So I have "File A", and I simply wish to copy it to another location within the Fileshare.  

How can I do this?  

I already know most of the basics, functions, etc. - but I just can't seem to find a (documented) way to copy a file.




SumanthMarigowda-MSFT on Sun, 11 Sep 2016 15:23:39

Hi Srikanth,

Thank you for posting here! We are happy to assist you.

Refer to the below mentioned link:

For more information on Microsoft Azure Storage SDK for Python. Click here

Sumanth BM

Peter Pan - MSFT on Mon, 12 Sep 2016 04:27:37


Thank you for posting here.

For copying file between locations within the file share, you can use the function copy_file of the class FileService of the module which wrapped the REST API Copy File.

As reference, here is my sample code.

from import CloudStorageAccount
from import FileService

account_name = '<your-storage-account>'
account_key = '<your-storage-account-key>'

source_share_name = '<source-share>'
source_dir_name = '<source-dir>'
source_file_name = '<source-file>'

target_share_name = '<target-share>'
target_dir_name = '<target-dir>'
target_file_name = '<target-file>'

account = CloudStorageAccount(account_name, account_key)

file_service = account.create_file_service()

# If target share & directory not exist
file_service.create_directory(target_share_name, target_dir_name)

# Get the url of the source file
source_url = file_service.make_file_url(source_share_name, source_dir_name, source_file_name)

# Copy File from source to target
file_service.copy_file(target_share_name, target_dir_name, target_file_name, source_url)

Hope it helps.

Best Regards,

Peter Pan

Srikant Krishna on Mon, 12 Sep 2016 23:25:50

Thank you.

Srikant Krishna on Mon, 12 Sep 2016 23:26:02

Thank you.

Srikant Krishna on Wed, 14 Sep 2016 19:14:51

Actually, I had one more question regarding this answer:

Where you have


file_service.copy_file(target_share_name, target_dir_name, target_file_name, source_url)

How can I determine the source_url of a given file using Fileshares?

Srikant Krishna on Wed, 14 Sep 2016 19:16:35

Actually, I got the answer:

https://<storage account><share>/<directory/directories>/<file>