How to delete files in Azure data lake store

In this post, let us see how to delete files in Azure data lake store using powershell and Azure CLI commands.


I have created Azure data lake store with account name trndls and uploaded some JSON files.


Using Powershell:


# Log in to your Azure account
 Login-AzureRmAccount

 # List all the subscriptions associated to your account
 Get-AzureRmSubscription

 # Select a subscription
 Set-AzureRmContext -SubscriptionId "subscription id"

 # Azure powershell command to delete multiple files by passing the file names separated by comma in -Paths argument
 Remove-AzureRmDataLakeStoreItem -AccountName "trndls" -Paths "/myfolder/Doc1.Json","/myfolder/Doc2.Json"

 # Azure powershell command to delete all files inside the folder
 Remove-AzureRmDataLakeStoreItem -AccountName "trndls" -Paths /myfolder -Recurse -Clean -Force

 # - Recurse - deletes all items in the target folder, including subfolders.
 # Unless you specify the Clean parameter, the target folder is also deleted

 # - Clean -  removes all of the contents of the target folder and retains the folder

 # - Force -  to run without asking for user confirmation


Using Azure CLI:

We can execute the Azure CLI commands from windows powershell.

# Log in to your Azure account
 az login
 # Authenticate from browser - https://aka.ms/devicelogin

 # Select a subscription
 az account set --subscription "subscription id"

 # Azure CLI command to delete all files including the folder
 az dls fs delete --account trndls --path /myfolder --recurse

See Also:

Reference:

No comments: