DataLakeDirectoryClient class

Definition

A client to interact with the DataLake directory, even if the directory may not yet exist.

For operations relating to a specific subdirectory or file under the directory, a directory client or file client can be retrieved using the get_sub_directory_client(sub_directory) or get_file_client(file) functions.

DataLakeDirectoryClient(account_url, file_system_name, directory_name, credential=None, **kwargs)
Inheritance
azure.storage.filedatalake._shared.base_client.StorageAccountHostsMixin
azure.storage.filedatalake._path_client.PathClient
DataLakeDirectoryClient

Parameters

account_url
str

The URI to the storage account.

file_system_name
str

The file system for the directory or files.

directory_name
str

The whole path of the directory. eg. {directory under file system}/{directory to interact with}

credential

The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, and account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.

Examples

Creating the DataLakeServiceClient from connection string.


   from azure.storage.filedatalake import DataLakeDirectoryClient
   DataLakeDirectoryClient.from_connection_string(connection_string, "myfilesystem", "mydirectory")

Variables

url
str
The full endpoint URL to the file system, including SAS token if used.
primary_endpoint
str
The full primary endpoint URL.
primary_hostname
str
The hostname of the primary endpoint.

Methods

create_directory

Create a new directory.

create_file

Create a new file and return the file client to be interacted with.

create_sub_directory

Create a subdirectory and return the subdirectory client to be interacted with.

delete_directory

Marks the specified directory for deletion.

delete_sub_directory

Marks the specified subdirectory for deletion.

from_connection_string

Create DataLakeDirectoryClient from a Connection String.

:return a DataLakeDirectoryClient :rtype ~azure.storage.filedatalake.DataLakeDirectoryClient

get_directory_properties

Returns all user-defined metadata, standard HTTP properties, and system properties for the directory. It does not return the content of the directory.

get_file_client

Get a client to interact with the specified file.

The file need not already exist.

get_sub_directory_client

Get a client to interact with the specified subdirectory of the current directory.

The sub subdirectory need not already exist.

rename_directory

Rename the source directory.

create_directory

Create a new directory.

create_directory(metadata=None, **kwargs)

Parameters

metadata
dict(str, str)
default value: None

Name-value pairs associated with the file as metadata.

Returns

response dict (Etag and last modified).

Examples

Create directory.


   directory_client.create_directory()

create_file

Create a new file and return the file client to be interacted with.

create_file(file, **kwargs)

Parameters

file
str or FileProperties
Required

The file with which to interact. This can either be the name of the file, or an instance of FileProperties.

Returns

DataLakeFileClient

create_sub_directory

Create a subdirectory and return the subdirectory client to be interacted with.

create_sub_directory(sub_directory, metadata=None, **kwargs)

Parameters

sub_directory
str or DirectoryProperties
Required

The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties.

metadata
dict(str, str)
default value: None

Name-value pairs associated with the file as metadata.

Returns

DataLakeDirectoryClient for the subdirectory.

delete_directory

Marks the specified directory for deletion.

delete_directory(**kwargs)

Returns

None

Examples

Delete directory.


   new_directory.delete_directory()

delete_sub_directory

Marks the specified subdirectory for deletion.

delete_sub_directory(sub_directory, **kwargs)

Parameters

sub_directory
str or DirectoryProperties
Required

The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties.

Returns

DataLakeDirectoryClient for the subdirectory

from_connection_string

Create DataLakeDirectoryClient from a Connection String.

:return a DataLakeDirectoryClient :rtype ~azure.storage.filedatalake.DataLakeDirectoryClient

from_connection_string(conn_str, file_system_name, directory_name, credential=None, **kwargs)

Parameters

conn_str
str
Required

A connection string to an Azure Storage account.

file_system_name
str
Required

The name of file system to interact with.

directory_name
str
Required

The name of directory to interact with. The directory is under file system.

credential
Required

The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, and account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

credential
default value: None

get_directory_properties

Returns all user-defined metadata, standard HTTP properties, and system properties for the directory. It does not return the content of the directory.

get_directory_properties(**kwargs)

Return type

DirectoryProperties

Examples

Getting the properties for a file/directory.


   props = new_directory.get_directory_properties()

get_file_client

Get a client to interact with the specified file.

The file need not already exist.

get_file_client(file)

Parameters

file
str or FileProperties
Required

The file with which to interact. This can either be the name of the file, or an instance of FileProperties. eg. directory/subdirectory/file

Returns

A DataLakeFileClient.

Return type

azure.storage.filedatalake..DataLakeFileClient

get_sub_directory_client

Get a client to interact with the specified subdirectory of the current directory.

The sub subdirectory need not already exist.

get_sub_directory_client(sub_directory)

Parameters

sub_directory
str or DirectoryProperties
Required

The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties.

Returns

A DataLakeDirectoryClient.

Return type

rename_directory

Rename the source directory.

rename_directory(new_name, **kwargs)

Parameters

new_name
str
Required

the new directory name the user want to rename to. The value must have the following format: "{filesystem}/{directory}/{subdirectory}".

Returns

DataLakeDirectoryClient

Examples

Rename the source directory.


   new_dir_name = "testdir2"
   print("Renaming the directory named '{}' to '{}'.".format(dir_name, new_dir_name))
   new_directory = directory_client\
       .rename_directory(new_name=directory_client.file_system_name + '/' + new_dir_name)