Introduction
In this article, we are going to discuss how to pick and delete only specific files from the ADLS directory based on filenames present inside the excel file. We are going to see this with a real-time use case.
File deletion
Recently I came across a requirement for file deletion in ADLS. Azure Data Factory’s delete activity is enough to complete this task, but the tricky part is the activity should delete only the objects that are present in the excel 'File Name' column. Let us see how this was achieved with a practical demo.
For this demo, I am going to upload few sample files including the ones which I am trying to delete into a folder in my ADLS Gen2 directory. Apart from this I must create an excel file that includes the filenames to be deleted present in column B; like below. One common question that might arrive here is how we can pick exactly the file name column if there are multiple columns present in the excel sheet. This can be achieved using the range option during creation of the source dataset which we will see in the next section.

File names in column B

Steps
Click and drag Lookup activity into your ADF pipeline canvas which is going to read out the file names that you want to be deleted.

Next go the settings tab and create the dataset which contain the excel file with the filename column. In the source dataset option click on +New and set file type as excel, then you will arrive at the following step.

- Path of the excel file which will function as source with all the filenames to be deleted.
- Select the sheet name if you excel sheet has more than one.
- Range is the one which you can mention to pick the cells starting and ending including the row and column name. In my case if you could scroll up the excel sheet screenshot you can see the filenames are present from column B cell 2 through 10, hence I have marked it as a range. In this way it will read only the specific data ignore all other which we do not need.
In range field, I have limited It to certain rows only as I know which column and up until which row the file names would be and that it will not be changing. In case you are going to append or delete the file names into the excel in future you can leave the range field open as ‘B2’ instead of ‘B2:B9’.








Join the conversation! Your thoughts help the community grow.