Reputation: 19250
I'm using the azure-storage-file-datalake plugin for Python 3.8. The SDK is described in great depth here -- https://learn.microsoft.com/en-us/python/api/azure-storage-file-datalake/azure.storage.filedatalake.datalakedirectoryclient?view=azure-python, but no where is there a description of whether you can delete a file from the data lake, the SDK only describes deleting directories. Is it possible to delete a file?
Edit: In response to the answer given, I tried this ...
file = DataLakeFileClient.from_connection_string(
my_connection_string,
file_system_name=filesystem,
file_path=path
)
file.delete_file()
but the last line results in this error
TypeError('element indices must be integers')
Upvotes: 1
Views: 4439
Reputation: 29995
Update:
First, I'm installing the latest python sdk for adls gen2. Using the command below:
pip install azure-storage-file-datalake==12.1.1
Here is my test code:
from azure.storage.filedatalake import DataLakeFileClient
conn_str="xxxx"
filesystem="aaa"
file_path="foo2.txt" #if the file is in a directory, like in directory test1, you should specify the path as "test1/foo2.txt"
fileClient = DataLakeFileClient.from_connection_string(
conn_str=conn_str,
file_system_name=filesystem,
file_path=file_path
)
fileClient.delete_file()
print("**completed**")
And the test result:
Original answer:
If you want to delete a file, you should take a look at DataLakeFileClient class. In this class, it has a delete_file
method. Please take a look at this article for its usage.
Or when you use DataLakeDirectoryClient class, you can get the file client by using get_file_client()
method of DataLakeDirectoryClient
instance, then call the delete_file()
method.
Please let me know if you still have more issues.
Upvotes: 2