1
votes

is there any simple way to copy data within Azure ADLS gen2 using Azure CLI, Rest API or Python?

Azure ADLS gen2 API documentation is very limited for now... https://docs.microsoft.com/en-us/rest/api/storageservices/data-lake-storage-gen2

1
Having same issue hereJosh D

1 Answers

1
votes

According to my research, we can use Azure CLI or python to move a directory or move a file. For more details, please refer to the document.

For example

  1. Install the storage CLI extension. Please note that the CLI version should be larger than 2.0.67
az extension add -n storage-preview
  1. Script
# move directory
az storage blob directory move -c my-file-system -d my-new-directory -s my-directory --account-name mystorageaccount

# move a file
az storage blob move -c my-file-system -d my-file-new.txt -s my-file.txt --account-name mystorageaccount

Python

try:

       file_system_client = service_client.get_file_system_client(file_system="my-file-system")
       directory_client = file_system_client.get_directory_client("my-directory")

       new_dir_name = "my-directory-renamed"
       directory_client.rename_directory(rename_destination=directory_client.file_system_name + '/' + new_dir_name)

    except Exception as e:
     print(e)