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_async.AsyncStorageAccountHostsMixinazure.storage.filedatalake.aio._path_client_async.PathClientDataLakeDirectoryClientazure.storage.filedatalake._path_client.PathClientazure.storage.filedatalake._data_lake_directory_client.DataLakeDirectoryClientDataLakeDirectoryClient
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.aio import DataLakeDirectoryClient
DataLakeDirectoryClient.from_connection_string(connection_string, "myfilesystem", "mydirectory")
Variables
- url
- str
- primary_endpoint
- str
- primary_hostname
- str
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. |
| 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)
Name-value pairs associated with the directory as metadata.
Returns
response dict (Etag and last modified).
Examples
Create directory.
await 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
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
The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties.
- metadata
- dict(str, str)
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.
await 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
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
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
Examples
Getting the properties for a file/directory.
props = await 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
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
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
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
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 = await directory_client\
.rename_directory(new_name=directory_client.file_system_name + '/' + new_dir_name)